Binary Tree

3592 ワード

#include <iostream>
using namespace std;
int main()
{
    int T, a, b,t, lcnt, rcnt;
    cin >> T;
    for(int i = 1; i <= T; ++i)
    {
        cin >> a >> b;
        lcnt = rcnt = 0;
        while(a>1 || b>1)
        {
            if(a >= b)
            {  t=(a-1)/b;
               lcnt+=t;;
                a -= b*t;
            }
            else
            {   t=(b-1)/a;
                rcnt+=t;
                b -= a*t;
            }
        }
        cout << "Scenario #" << i << ':' << endl;
        cout << lcnt << ' ' << rcnt << endl <<endl;
    }
    return 0;
}