http://poj.org/problem?id=2499
1 #include<stdio.h> 2 int main() 3 { 4 int t,a,b; 5 scanf("%d",&t); 6 for (int i = 1; i <= t; i ++) 7 { 8 int l = 0,r = 0; 9 scanf("%d%d",&a,&b); 10 while(a!=1&&b!=1) 11 { 12 13 if(a > b) 14 { 15 l += a/b; 16 a = a % b; 17 } 18 else 19 { 20 r += b/a; 21 b = b % a; 22 } 23 } 24 if(a==1) 25 r+=b-a; 26 if(b==1) 27 l+=a-b; 28 printf("Scenario #%d: %d %d ",i,l,r); 29 if(i!=t) 30 printf(" "); 31 32 } 33 return 0; 34 }