题意很好理解,也不算多么难的题目。
以下是我的代码:
#include<cstdio>
using namespace std;
int Gcd(int a,int b)
{
for(int t=a%b;t;a=b,b=t,t=a%b);return b;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.in","r",stdin);
#endif
int a,b;
while(scanf("%d%d",&a,&b)==2 && (a!=1 || b!=1))
{
int l1(0),l2(1),now1(1),now2(1),r1(1),r2(0);
while(now1*b!=now2*a)
{
if(now1*b<now2*a)
{
printf("R");
l1=now1;
l2=now2;
now1=l1+r1;
now2=l2+r2;
int d(Gcd(now1,now2));
now1/=d;
now2/=d;
}
else if(now1*b>now2*a)
{
printf("L");
r1=now1;
r2=now2;
now1=l1+r1;
now2=l2+r2;
int d(Gcd(now1,now2));
now1/=d;
now2/=d;
}
}
printf("\n");
}
return 0;
}
posted on 2011-08-29 15:06
lee1r 阅读(427)
评论(0) 编辑 收藏 引用 所属分类:
题目分类:数学/数论