POJ 1909 Count on Canton
来源:互联网 发布:大数据 利与弊 编辑:程序博客网 时间:2024/05/22 15:23
A - Count on Canton
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64uDescription
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/4 3/1 3/2 3/3 4/1 4/2 5/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
#include<stdio.h>#include<string.h>int main(){ int n,m,i,j; int count; while(scanf("%d",&n)!=EOF) { int sum = 0; count = 0; for(i=1;i<n;i++) { sum = sum + i; if(sum >=n) { count = sum - n; //printf("count = %d\n",count); if((i+1)%2 == 0) { printf("TERM %d IS %d/%d\n",n,1+count,i-count); break; } else { printf("TERM %d IS %d/%d\n",n,i-count,1+count); break; } } } } return 0;}
0 0
- POJ 1909 Count on Canton
- poj 1969 Count on Canton
- POJ-1969-Count on Canton
- zoj 2185 || poj 1969 Count on Canton
- poj 1969 Count on Canton 摘规律
- POJ 1969---Count on Canton【数学问题】
- POJ 1969 Count on Canton 笔记
- hoj Count on Canton
- Count on Canton
- Count on Canton
- Count on Canton
- Count on Canton
- POJ 1969 Count on Canton(数学题,找规律)
- zoj 2185 Count on Canton
- HOJ 1649 Count on Canton
- ZOJ 2185 Count on Canton
- No.1969 Count on Canton (ACM)
- UVA 264 Count on Canton 找规律
- Cstyle的札记,Freertos内核详解,第2篇
- MAT 内存分析
- eclipse svn插件的安装与使用
- Android界面--一些xml属性
- hdu4135(容斥原理入门题)
- POJ 1909 Count on Canton
- 各种排序方法源码及复杂度分析(二)
- POJ 3084 Panic Room | 最小割
- SP申请业务方案编写模板
- JavaScript演示Math对象
- HDU 2544 最短路(我的dijkstra算法模板、SPAFA算法模板)
- Cstyle的札记,Freertos内核详解,第3篇
- D - Pots
- HDU 4891— The Great Pan