forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10049.cpp
67 lines (60 loc) · 760 Bytes
/
10049.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
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
#include <bits/stdc++.h>
using namespace std;
#define MAX 4387500
typedef long long ss;
ss F[MAX + 3], G[MAX + 3];
void Gen()
{
ss i, a, b, sum = 1;
G[1] = F[1] = 1;
for (i = 2; sum <= 2000000000; i++)
{
a = F[i - 1];
a = F[a];
b = i - a;
b = F[b] + 1;
F[i] = b;
sum += b;
G[i] = sum;
}
}
// bin srch
ss Find(ss key)
{
ss lo = 1, up = 673366;
ss mid = (lo + up) / 2;
while (lo < up && G[mid] != key)
{
if (key > G[mid])
{
lo = mid + 1;
}
else
{
if (G[mid - 1] < key)
{
return mid;
}
else
{
up = mid - 1;
}
}
mid = (lo + up) / 2;
}
return mid;
}
int main()
{
Gen();
ss n;
while (scanf("%lld", &n) == 1)
{
if (n == 0)
{
break;
}
printf("%lld\n", Find(n));
}
return 0;
}