-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path026.cpp
executable file
·42 lines (42 loc) · 890 Bytes
/
026.cpp
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
#include <iostream>
#include <vector>
#define MIN 2
#define MAX 1000
using namespace std;
short findN(vector<short> v, short n) {
short size = v.size();
for (short i = 0; i < size; i++) if (v[i] == n) return i;
return -1;
}
short optimize(short n, short d) {
if (n != 0) while (n < d) n *= 10;
return n;
}
short cLength(short d) {
vector<short> remainders;
short firstN = optimize(1, d);
short n = firstN % d;
short count = 0;
while (n != 0) {
short c = findN(remainders, n);
if (c > -1) return remainders.size() - c;
remainders.push_back(n);
n = optimize(n % d, d);
count++;
}
return 0;
}
int main() {
short maxLength = 0;
short d;
short maxD;
for (d = MIN; d < MAX; d++) {
short thisLength = cLength(d);
if (thisLength > maxLength) {
maxLength = thisLength;
maxD = d;
}
}
cout << maxD << endl;
return 0;
}