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
3Output
2Input
5Output
2Input
10Output
4Input
55Output
10Input
56Output
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]
相关文章推荐
- 《NumPy Beginner's Guide》笔记Chapter2
- UI控件--UIImageView
- UVa 540 - Team Queue
- 《iOS Human Interface Guidelines》——Image View
- 对于League of Legends的分析
- Hibernate之Query接口的uniqueResult()方法
- UIviewcontroller与UIview
- [手游新项目历程]第3天-fatal error LNK1000: Internal error during IncrBuildImage
- iOS上传失败提示"Request failed: unacceptable content-type: text/html"
- String,StringBuffer与StringBuilder之间的区别
- UIscrollView和UIPageControl的循环滚动
- MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 有什么区别?各适用于什么场合?
- Easyui datebox 限制时间选择范围
- 通过xib加载UITableViewCell的新方式
- 切换Fragment时避免重复加载UI
- NameValuePair在API22过时问题
- 使用 JDBC 连接 Hive(ClassNotFoundException、No suitable driver found、Could not open client transport wit)
- [LeetCode]232. Implement Queue using Stackssil
- Farey Sequence
- Builder模式