您的位置:首页 > 产品设计 > UI/UE

Codeforces--622A--Infinite Sequence(数学)

2016-03-12 13:15 656 查看
Infinite SequenceCrawling in process...Crawling failedTime Limit:1000MSMemory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmitStatusPracticeCodeForces 622ADescriptionConsider 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 from1 to 2, then the numbers from1 to 3, then the numbers from1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number10 first appears in the sequence in position55 (the elements are numerated from one).Find the number on the n-th position of the sequence.InputThe 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 use64-bit integer type to store it. In C++ you can use thelong long integer type and inJava you can use long integer type.OutputPrint the element in the n-th position of the sequence (the elements are numerated from one).Sample InputInput
3
Output
2
Input
5
Output
2
Input
10
Output
4
Input
55
Output
10
Input
56
Output
1
有这样一个序列,1,1,2,1,2,3,,,,,输出数列中的第n个数
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){__int64 n;while(cin>>n){__int64 temp;for(__int64 i=1;n>0;i++){temp=n;n-=i;}cout<<temp<<endl;}return 0;}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: