forked from Manish57-droid/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgg.cpp
More file actions
45 lines (37 loc) · 959 Bytes
/
gg.cpp
File metadata and controls
45 lines (37 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// C++ program for finding maximum multiple
// of a number with all the digits same
#include <bits/stdc++.h>
using namespace std;
// Function for calculating maximum
// multiple of X less than 10^Y
string maxMultiple(int X, int Y)
{
// f(n, d) -> d digit is repeated
// n times (ddd....d)
pair<int, int> res = { 0, 0 };
int number = 0;
for (int d = 1; d <= 9; ++d) {
for (int n = 1; n <= Y; ++n) {
number = (10 * number + d) % X;
if (number == 0)
res = max(res, { n, d });
}
}
// No such multiple exits so return -1
if (res.first == 0)
return "-1";
// Generating the multiple
// from pair res
string ans = "";
for (int i = 1; i <= res.first; i++)
ans += (res.second + '0');
return ans;
}
// Driver function
int main()
{
int X = 12, Y = 7;
// Function Call
cout << maxMultiple(X, Y);
return 0;
}