CodeForces 622A Infinite Sequence
来源:互联网 发布:用友软件银川经销处 编辑:程序博客网 时间:2024/03/29 12:44
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 number 1 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 number 10 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 the long 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
AC代码:
#include<stdio.h>int main(){__int64 n;while(scanf("%I64d",&n)!=EOF){__int64 i,t;for(i=0;i<=20000000;i++){if(i*(i+1)/2==n){ printf("%I64d\n",i); break;}else if(i*(i+1)/2>n){ printf("%I64d\n",n-(i-1)*i/2);break;}}}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
- Android SurfaceView双缓冲绘图
- poj3349 Snowflake Snow Snowflakes之hash入门
- 蓝桥杯--移动距离
- 夯实JAVA基本之一——泛型详解(2):高级进阶
- Nssting
- CodeForces 622A Infinite Sequence
- Android实现图片(拍照+相册)上传功能
- ppp and ndis
- 一些基础博客链接
- 测试代码格式
- Android 6.0 反射 newInstance
- NSLayoutConstraint-代码实现自动布局的函数用法
- 通过寄生组合式继承创建js的异常类
- 极光推送参考文档