-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamp.c
61 lines (54 loc) · 1.55 KB
/
stamp.c
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
#include <stdio.h>
#include <math.h>
void find(long long, long long);
int main(){
long long max, cash;
scanf("%lld%lld", &max, &cash);
find(max, cash);
return 0;
}
void find(long long max, long long cash){
int dimension = 0;
int copy = cash;
int half[2];
int has_shown = 0;
while((copy % 2) == 0){
copy /= 2;
dimension++;
}
if((copy / 2) - (int) pow(2, dimension) + 1 <= 0){
half[0] = 0;
half[1] = 0;
} else {
half[0] = copy / 2 - (long long) pow(2, dimension) + 1;
half[1] = copy / 2 + 1 + (long long) pow(2, dimension) - 1;
}
long long limit = max > (cash / 2 + 1) ? (cash / 2 + 1) : max;
for(long long count = 2; count < limit; count++){
if((cash % count) == 0){
long long less = count;
long long bigger = cash / count;
if(bigger % 2 == 0){
continue;
} else {
long long former = less - bigger / 2;
long long latter = less + bigger / 2;
if(former <= 0){
continue;
} else {
if(half[0] && !has_shown && former > half[0]){
printf("[%d,%d]\n", half[0], half[1]);
has_shown = 1;
}
printf("[%d,%d]\n", former, latter);
}
}
}
}
if(!has_shown){
printf("[%d,%d]\n", half[0], half[1]);
}
if(cash <= max){
printf("[%d,%d]\n", cash, cash);
}
}