A. Infinite Sequence

题目连接:

http://www.codeforces.com/contest/622/problem/A

Description

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

10

Sample Output

4

Hint

题意

数列是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;
}

最新文章

  1. MySQL命令实例
  2. VS开发中的代码编写小技巧&mdash;&mdash;避免重复代码编写的几种方法
  3. hdu 1028 Ignatius and the Princess III 简单dp
  4. PHP 冒泡原理
  5. Greedy:Cleaning Shifts(POJ 2376)
  6. weka数据预处理
  7. shell语句记录-awk
  8. 学习hash_map从而了解如何写stl里面的hash函数和equal或者compare函数
  9. Google正确搜索方法
  10. basename usage in linux
  11. css white-space
  12. centos安装如何选择安装包
  13. json恶补
  14. Coloring Trees
  15. C++动态内存管理之深入探究new和delete
  16. python实现时间o(1)的最小栈
  17. 补充:MySQL经典45道题型
  18. 【题解】 bzoj3036: 绿豆蛙的归宿 (期望dp)
  19. css文字效果(文字剪贴蒙版,text-shodow的应用,文字排版等…)
  20. JVM内存管理(转)

热门文章

  1. Ajax实现搜索栏中输入时的自动提示功能
  2. bjfu1277 简单递归
  3. 设计模式 外观 Facade
  4. C/C++——C++变量的作用域与生命周期,C语言中变量的作用域和生命周期
  5. 免费CDN
  6. ASP.NET MVC3 系列教程 - 部署你的WEB应用到IIS 6.0
  7. 调用openoffice Com组件转换成PDF
  8. 分享一个自己用的Objective-C的Http接连类
  9. geeksforgeeks@ Minimum Points To Reach Destination (Dynamic Programming)
  10. Educational Codeforces Round 5 A. Comparing Two Long Integers