題目描述 Description
現(xiàn)代數(shù)學(xué)的著名證明之一是Georg Cantor證明了有理數(shù)是可枚舉的。他是用下面這一張表來證明這一命題的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … 3/1 3/2 3/3 … 4/1 4/2 … 5/1 … … 我們以Z字形給上表的每一項(xiàng)編號。第一項(xiàng)是1/1捏鱼,然后是1/2筒溃,2/1拄丰,3/1晌端,2/2谚殊,…
輸入描述 Input Description
整數(shù)N(1≤N≤10000000)
輸出描述 Output Description
表中的第N項(xiàng)
樣例輸入 Sample Input
7
樣例輸出 Sample Output
1/4
代碼
#include<stdio.h>
int main()
{
int i=0,n,tag=0,a=2,b=0;
scanf("%d",&n);
while(i!=n){
if(tag){
while(b!=1){
a++;
b--;
i++;
if(i==n)
goto out;
}
a++;
i++;
tag=0;
}
else{
while(a!=1){
a--;
b++;
i++;
if(i==n)
goto out;
}
b++;
i++;
tag=1;
}
}
out:
printf("%d/%d",a,b);
return 0;
}