CodeForces 622A-Infinite Sequence
来源:互联网 发布:知乎回答怎么复制 编辑:程序博客网 时间:2024/04/27 07:18
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the n-th position of the sequence.
The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use thelong long integer type and in Java you can use long integer type.
Print the element in the n-th position of the sequence (the elements are numerated from one).
3
2
5
2
10
4
55
10
56
1
#include<stdio.h>#define LL __int64int main(){LL n;scanf("%I64d",&n);if(n==1){printf("1\n");}else{LL i,j=1;for(i=1;(i*(i+1))<2*n;i++){j=i;}j++;LL uu=j*(j-1)/2;printf("%I64d",n-uu); }return 0;}
- Codeforces 622A Infinite Sequence
- CodeForces 622A Infinite Sequence
- CodeForces 622A Infinite Sequence
- CodeForces 622A Infinite Sequence
- CodeForces 622A-Infinite Sequence
- CodeForces 622A Infinite Sequence
- CodeForces-622A.Infinite Sequence
- Codeforces 622A Infinite Sequence 【数学】
- CodeForces 622 A. Infinite Sequence(水~)
- Codeforces--622A--Infinite Sequence(数学)
- CodeForces 622A:Infinite Sequence【排列】
- CodeForces 622A--F - Infinite Sequence
- codeforces 675A Infinite Sequence
- CodeForces 675 A Infinite Sequence
- 【CodeForces】675A - Infinite Sequence
- 【CodeForces】[675A]Infinite Sequence
- CodeForces 675 A Infinite Sequence
- [CodeForces]-675A-Infinite Sequence
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- shell函数返回值(执行状态)的获取
- iOS开发判断是否是身份证号
- pdflib textflow
- Vector删除指定元素
- CodeForces 622A-Infinite Sequence
- Hust oj 1073 病毒(并查集)
- Android Parcelable和Serializable的区别
- 通过子div覆盖父div的border-bottom
- python编辑器sublime
- iOS 【读取图片数据 UIImageJPEGRepresentation和UIImagePNGRepresentation】
- Fiddler中显示IP的设置方法
- css 画矩形
- glob 文件路径查找