题目链接:https://vjudge.net/contest/362170#problem/F
题目大意:
告诉你终点是(ex,ey) ,问你可能的起点的个数 ( 如果起点是(x,y) 那么你去的下一个点是 (x+z,y) 或者 (x,y+z) z = lcm(x,y) )
想法:
参考博客:https://blog.csdn.net/yuzhiwei1995/article/details/51100389
LL gcd(LL a,LL b) { LL t; while (b) { t = b; b = a % b; a = t; } return a; } int main() { int T; scanf("%d",&T); int t = 1; while (T--) { LL a,b; scanf("%lld%lld",&a,&b); LL GCD = gcd(a,b); LL m1 = a / GCD; LL m2 = b / GCD; LL ans = 1; while (1) { if (m1 < m2) swap(m1,m2); if (m1 % (1 + m2) == 0) { m1 = m1 / (1 + m2); ans++; } else break; } printf("Case #%d: %lld ",t++,ans); } return 0; }