jzoj 2322 capacitor
Description–
Input–
Output–
Sample Input–
样例1
2
1 1
3 2
样例2
2
6 5
199 200
Sample Output–
样例1
1
3
样例2
6
200
说明–
代码–
#include<iostream>
#include<cstdio>
using namespace std;
long long a, b, t, tt, ans;
int main()
{
freopen("capacitor.in", "r", stdin);
freopen("capacitor.out", "w", stdout);
scanf("%d", &t);
for (int i = 1; i <= t; ++i)
{
ans = 0;
scanf("%lld%lld", &a,&b);
long long x = a, y = b, r = x % y;
while (r)//最大公约数
{
x = y, y = r;
r = x % y;
}
a /= y, b /= y;
if (a < b) tt = a, a = b, b = tt;
while (b != 1)
{
a -= b, ans++;
if (a < b) tt = a, a = b, b = tt;
}
printf("%lld\n", a + ans);
}
return 0;
}