本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年3月16日 星期三

[UVa]264:Count on Cantor

找出第幾斜排以及第幾斜排的最末項還有第n項的分母與分子這四者的關係,
即可得解。

[C](0.012)
#include<stdio.h>
int main()
{
int n;
while( scanf( "%d", &n ) != EOF )
{
int slash = 1;
int term = 1;
while( term < n )
term += (++slash);
int up, down;
if( slash % 2 )
{
up = ( term - n ) + 1;
down = slash - ( term - n );
}
else
{
up = slash - ( term - n );
down = ( term - n ) + 1;
}
printf( "TERM %d IS %d/%d\n", n, up, down );
}
return 0;
}
view raw UVa264.c hosted with ❤ by GitHub

0 意見:

張貼留言