CodeForces 622A-Infinite Sequence
2016-03-14 18:03
465 查看
A. Infinite Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
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.
Output
Print the element in the n-th position of the sequence (the elements are numerated from one).
Examples
Input
Output
Input
Output
Input
Output
Input
Output
Input
Output
[/code]
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
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.
Output
Print the element in the n-th position of the sequence (the elements are numerated from one).
Examples
Input
3
Output
2
Input
5
Output
2
Input
10
Output
4
Input
55
Output
10
Input
56
Output
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;
}
[/code]
相关文章推荐
- iOS UITableView滑动时NSTime停止重复利用RunLoop解决
- BlockingQueue
- Java源码阅读之PriorityBlockingQueue
- IOS学习 触摸和手势UITouch 捏合
- CodeForces 622A Infinite Sequence
- 可变字符串改变颜色大小
- UE4 添加多人联机功能
- UE4 添加多人联机功能
- UILabel的minimumScaleFactor
- EasyUI-draggable
- Basic build issue regarding libs, pkg-config and opencv
- IOS UICollectionView 的基础使用
- 根据sql的hash_value查看sql的正直执行计划
- UIButton设置内容setTitle
- 自定义UISearchBar
- 【HDU】 5538 House Building
- 自定义UITableViewCell(registerNib: 与 registerClass: 的区别)
- Android UiAutomator 初试。
- UITableView的总结
- IOS学习 触摸和手势UITouch 单击双击、移动视图