Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

辗转相除法,贴代码

Posted by husanfeng at 2012-11-30 21:45:40 on Problem 2499
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int n,a,b,l,r,temp;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        l=r=0;      
        scanf("%d%d",&a,&b);
        while(a!=1||b!=1)
        {
            if(a>b)
            {
                temp=(a-1)/b;
                l+=temp;
                a-=temp*b;
            }
            else 
            {
                temp=(b-1)/a;
                r+=temp;
                b-=temp*a;
            }
        }
        printf("Scenario #%d:\n",i);
        printf("%d %d\n",l,r);
        if(i<n) printf("\n");
    }                                   
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator