思路:找一下规律,就是一个类似辗转相除法的东西...
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
ll a, b;
ll get(ll A, ll B)
{
if(B==0) return 1;
ll t = A%B, ans=0;
ans = A/B + get(B, t);
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int ca=1,tt;
scanf("%d", &tt);
while(ca<=tt)
{
scanf("%lld%lld", &a, &b);
if(b>a) swap(a, b);
if(a!=0&&b==0) printf("Case #%d: %lld\n", ca++, 2);
else printf("Case #%d: %lld\n", ca++, get(a, b));
}
return 0;
}