Sunday, February 27, 2011

264 - Count on Cantor


#include<stdio.h>
int main()
{
    register long n,x,y,sum,i,j,s;
    //freopen("in.txt","r",stdin);
    while(scanf("%ld",&n)==1)
    {
        sum=0;
        for(i=1;sum<n;i++)
            sum=sum+i;
        sum=sum-i+1;
        s=n-sum;
        if(i&1)
            x=s,y=i-s;
        else
            x=i-s,y=s;
        printf("TERM %ld IS %ld/%ld\n",n,x,y);
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.