-
Notifications
You must be signed in to change notification settings - Fork 2
/
10170.cpp
54 lines (45 loc) · 848 Bytes
/
10170.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
#include<stdio.h>
#include<math.h>
typedef unsigned long long Big;
Big St, TDay;
Big Val(Big g) {
Big v;
v = 2 * (St-1)* g + ( g *(g+1));
return v;
}
Big Search() {
Big temp, dummy, hi, low, mid;
long long key;
key = TDay * 2;
temp = 2*(St - 1);
dummy = temp*1 + (1 * (1+1));
if(dummy >= TDay * 2) return 1;
low = 1; hi = sqrt(key)+1;
mid = ( 1+ hi) / 2;
dummy = temp*mid + (mid * (mid+1));
while(hi > low && dummy != key) {
if(dummy > key) {
if(Val(mid-1) < key)
return mid;
hi = mid-1;
}
else
low = mid+1;
mid = (hi + low) / 2;
dummy = temp*mid + (mid * (mid+1));
}
return mid;
}
void Cal() {
printf("%llu\n",Search()+St - 1);
}
int main() {
while(scanf("%llu%llu",&St,&TDay) == 2) {
if(St >= TDay) {
printf("%llu\n",St);
continue;
}
Cal();
}
return 0;
}