Count on Canton
来源:互联网 发布:西安星河网络小贷 编辑:程序博客网 时间:2024/06/06 00:29
Count on Canton
Time Limit: 1000MS
Memory Limit: 30000KTotal Submissions: 9142
Accepted: 5357
Memory Limit: 30000KTotal Submissions: 9142
Accepted: 5357
Description
One of the famous proofs of modern mathematics is Georg Cantor's demonstration that the set of rational numbers is enumerable. The proof works by using an explicit enumeration of rational numbers as shown in the diagram below.
In the above diagram, the first term is 1/1, the second term is 1/2, the third term is 2/1, the fourth term is 3/1, the fifth term is 2/2, and so on.
1/1 1/2 1/3 1/4 1/5 ...2/1 2/2 2/3 2/43/1 3/2 3/34/1 4/25/1
In the above diagram, the first term is 1/1, the second term is 1/2, the third term is 2/1, the fourth term is 3/1, the fifth term is 2/2, and so on.
Input
The input list contains a single number per line and will be terminated by endof-file.
Output
You are to write a program that will read a list of numbers in the range from 1 to 10^7 and will print for each number the corresponding term in Cantor's enumeration as given below.
Sample Input
3147
Sample Output
TERM 3 IS 2/1TERM 14 IS 2/4TERM 7 IS 1/4
Source
Southeastern Europe 2004
<strong><span style="color:#009900;"><span style="font-size:14px;">#include <iostream>#include<stdio.h>#include<math.h>#include<string.h>using namespace std;int a[1000000];int main(){ int i,n,m,k,x,y; a[1]=1; for(i=2;i<=1000000;i++) { a[i]=a[i-1]+i;//将每一斜层的和求出 } while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { if(n>=a[i]&&n<=a[i+1])//判断属于哪一层 { m=n-a[i]; k=i; break; } } x=k+2-m;y=m; if(k%2==0) printf("TERM %d IS %d/%d \n",n,x,y); else printf("TERM %d IS %d/%d \n",n,y,x); }</span>}</span></strong>
0 0
- hoj Count on Canton
- Count on Canton
- Count on Canton
- Count on Canton
- Count on Canton
- zoj 2185 Count on Canton
- poj 1969 Count on Canton
- HOJ 1649 Count on Canton
- ZOJ 2185 Count on Canton
- POJ 1909 Count on Canton
- POJ-1969-Count on Canton
- No.1969 Count on Canton (ACM)
- zoj 2185 || poj 1969 Count on Canton
- poj 1969 Count on Canton 摘规律
- POJ 1969---Count on Canton【数学问题】
- UVA 264 Count on Canton 找规律
- POJ 1969 Count on Canton 笔记
- POJ 1969 Count on Canton(数学题,找规律)
- leetcode 刷题之路 46 Set Matrix Zeroes
- java连接mongodb数据库
- 面向.Net程序员的前端优化
- 字符理论--Unicode详解
- Java经典算法大全
- Count on Canton
- Objective-C NSString
- android soundrecorder之三 录音流程及数据流向
- 获取、设置声卡音量的方法
- 如果我有jQuery背景,我怎样“用AngularJS思考”?
- 矩阵十题【一】点的变换
- FlowVisor介绍
- sorl config.xml 简单介绍
- voj1451 环形dp 记忆化搜索