-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc2016E.cpp
More file actions
76 lines (65 loc) · 2.02 KB
/
icpc2016E.cpp
File metadata and controls
76 lines (65 loc) · 2.02 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL convertbase(LL origin, LL base) {
LL result = 0;
LL t = origin;
LL thisv;
int d10 = 1;
while (t > 0) {
thisv = t % base;
if (thisv > 9) return -1;
result += thisv * d10;
t /= base;
d10 *= 10;
}
return result;
}
int main() {
// freopen("input.txt", "r", stdin);
LL y, l, tmp;
LL base;
while (scanf("%lld%lld", &y, &l) != EOF) {
base = 10;
for (LL i = 10; i <= 1000000; ++i) {
tmp = convertbase(y, i);
if (tmp != -1 && tmp >= l) {
base = i;
}
}
for (LL a0 = 0; a0 < 10; ++a0) {
for (LL a1 = 0; a1 < 10; ++a1) {
for (LL a2 = 0; a2 < 10; ++a2) {
for (LL a3 = 0; a3 < 10; ++a3) {
if (a3 * 1000 + a2 * 100 + a1 * 10 + a0 < l) continue;
LL head = 11, tail = 1e18 + 10, m;
while (head < tail) {
m = (head + tail) >> 1;
double d = m;
if (a3 * d * d * d + a2 * d * d + a1 * d + a0 > 1e18) {
tail = m - 1;
}
else if (a3*m*m*m + a2*m*m + a1*m + a0 > y) {
tail = m - 1;
}
else
head = m + 1;
if (a3*m*m*m + a2*m*m + a1*m + a0 == y) {
head = m;
break;
}
}
m = head;
if (a3*m*m*m + a2*m*m + a1*m + a0 == y) {
base = max(base, m);
}
}
}
}
}
printf("%lld\n", base);
}
return 0;
}