uva-10077 Solution --- The Stern-Brocot Number System
using namespace std;
int main(){
int input_num,input_den,left_num,left_den,right_num,right_den,cur_num,cur_den;
while(cin>>input_num>>input_den){
if(input_num==1 && input_den==1)
break;
left_num=0;
left_den=1;
right_num=1;
right_den=0;
cur_num=cur_den=1;
while(true){
if(cur_num== input_num && cur_den==input_den)
break;
if(cur_num*input_den < cur_den*input_num){
cout<<"R";
left_num=cur_num;
left_den=cur_den;
cur_num+=right_num;
cur_den+=right_den;
}else{
cout<<"L";
right_num=cur_num;
right_den=cur_den;
cur_num+=left_num;
cur_den+=left_den;
}
}
cout<<endl;
}
return 0;
}
Comments
Post a Comment