Pages

Saturday 13 October 2012

UVA - 10077 - The Stern-Brocot Number System

#include <stdio.h>

int main()
{
    int a,b;
    while(1){
        int xR=1,yR=0,xL=0,yL=1;
        scanf("%d %d",&a,&b);
        if(a==1 && b==1)
            break;
        int tempX=1,tempY=1;
        while(!(a==tempX && b==tempY)){
            if(tempX*b>tempY*a){
                xR=tempX;
                yR=tempY;
                printf("L");
            }else{
                xL=tempX;
                yL=tempY;
                printf("R");
            }
            tempX=xL+xR;
            tempY=yL+yR;
        }
        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment