Educational Codeforces Round 7 A. Infinite Sequence 水题
2016-02-12 14:24
393 查看
A. Infinite Sequence
题目连接:
http://www.codeforces.com/contest/622/problem/ADescription
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).Sample Input
10Sample Output
4Hint
题意
数列是1,1,2,1,2,3,1,2,3,4,1,2,3,4,5这样的给你n,让你输出第n个数是什么
题解:
水题代码
#include<bits/stdc++.h> using namespace std; int main() { long long n = 1; long long x; cin>>x; while(x>n) { x-=n; n++; } cout<<x<<endl; }
相关文章推荐
- POJ 2623 Sequence Median(水~)
- 303. Range Sum Query - Immutable LeetCode
- UIView不接受触摸事件的三种情况:
- Educational Codeforces Round 7(D)构造(STL deque)
- Light OJ 1126 Building Twin Towers (DP)
- Building Maintainable Software-java篇之Write Short Units of Code
- deque 双端队列。
- PHP:数组操作函数array_count_values()的实现
- ELK setup guide
- Java中序列化的serialVersionUID作用
- 【CodeForces 618B】Guess the Permutation
- HDU 3732 Ahui Writes Word(01背包转化为多重背包)
- E - Number Sequence(第二季水)
- css3 Media Query IE6-8兼容问题
- UITableView细节.txt
- async 异步进度条,防UI卡顿
- 225. Implement Stack using Queues LeetCode
- 【leetcode】Array——Unique Paths II(63)
- 【leetcode】Array——Unique Paths(62)
- iOS之加速计、陀螺仪(UIAccelermeter、Core Motion)