您的位置:首页 > 其它

Code[vs] 1083 Cantor表

2015-08-05 18:28 435 查看
题目描述 Description

现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的。他是用下面这一张表来证明这一命题的: 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字形给上表的每一项编号。第一项是1/1,然后是1/2,2/1,3/1,2/2,…



输入描述 Input Description

整数N(1≤N≤10000000)

输出描述 Output Description

表中的第N项

样例输入 Sample Input

7

样例输出 Sample Output

1/4
#include <iostream>

#include <string>

#include <algorithm>

#include <stdio.h>

#include <math.h>

using namespace std;

int main()

{

int N;

cin>>N;

long long Pai=int(sqrt(8*N+1)-1)/2;//算出是第几斜排

long long ShengYu=N-Pai*(Pai+1)/2;

int ant=ShengYu==0?Pai:Pai+1;

if(ShengYu==0)ShengYu=ant;

if(ant%2==0)

cout<<(1+ShengYu-1)<<"/"<<(ant-ShengYu+1)<<endl;

else

cout<<(ant-ShengYu+1)<<"/"<<(1+ShengYu-1)<<endl;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: