Wednesday, 18 May 2011

264-Count on Cantor

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

1 comment:

  1. you have wrong answer here http://www.spoj.pl/problems/CANTON/

    ReplyDelete