| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
辗转相除法,贴代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator