您的位置:首页 > 其它

hdu 5584 LCM Walk(规律)

2015-12-03 21:02 225 查看
题目链接:hdu 5584 LCM Walk

代码

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
int a, b, c = 1, d;
scanf("%d%d", &a, &b);
d = gcd(a, b);
a /= d, b /= d;
while (true) {
if (a > b) swap(a, b);
if (b % (a + 1)) break;
b /= (a + 1);
c++;
}
printf("Case #%d: %d\n", kcas, c);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: