您的位置:首页 > Web前端

Last Defence - UVA7045

2015-10-10 15:24 351 查看
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5057

不知道为什么是这个规律

#include <iostream>
using namespace std;
long long a, b, ans;
int nCase, cCase;
long long calc(long long a, long long b)
{
long long ret = 0;
while (b)
{
long long t = b;
ret += a / b;
b = a % b;
a = t;
}
return ret + 1;
}
int main()
{
//ios::sync_with_stdio(false);
cin >> nCase;
while (nCase--)
{
cin >> a >> b;
if (a == 0 && b == 0)
{
ans = 1;
}
else if (a == 0 || b == 0)
{
ans = 2;
}
else
{
ans = calc(a, b);
}
cout << "Case #" << ++cCase << ": " << ans << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: