-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc7411.cpp
More file actions
34 lines (28 loc) · 701 Bytes
/
Copy pathicpc7411.cpp
File metadata and controls
34 lines (28 loc) · 701 Bytes
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
#include <cstdio>
int gcd(int a, int b) {
if(b > a) return gcd(b, a);
if(b == 0) return a;
return gcd(b, a%b);
}
int solve(int ex, int ey, int gcr) {
if(ex < 1 || ey < 1 || gcd(ex, ey) != gcr) return 0;
int vl = 0, vr = 0;
int dx = ey/gcr+1;
int dy = ex/gcr+1;
if(ey%dy == 0)
vl = solve(ex, ey/dy, gcr);
if(ex%dx == 0)
vr = solve(ex/dx, ey, gcr);
return vl+vr+1;
}
int main() {
// freopen("input.txt", "r", stdin);
int t, ex, ey;
scanf("%d", &t);
for(int nt = 1; nt <= t; ++nt) {
scanf("%d%d", &ex, &ey);
int gcr = gcd(ex, ey);
printf("Case #%d: %d\n", nt, solve(ex, ey, gcr));
}
return 0;
}