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
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,1,2,3,4,1,2,3,4,5 .....以此类推给你一个数n问第n个数是多少
题解:由题知数列的数的个数为1+2+3+4+5+6+.......所以求出第n个数是哪个子序列里的即可(第一个子序列中一个数第二个字序列里两个数第三个里三个数....)
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 5100
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
LL n,m,j,i,k,t,ans;;
while(scanf("%lld",&n)!=EOF)
{
ans=0;
for(i=1;i<2*sqrt(n)+1;i++)
{
if((i*(i+1)/2)>=n)
{
ans=i;
break;
}
}
m=ans*(ans-1)/2;
m=n-m;
printf("%lld\n",m);
}
return 0;
}

  

codeforces 622A Infinite Sequence的更多相关文章

  1. codeforces 622A A. Infinite Sequence (二分)

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  3. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  4. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. codeforces 675A A. Infinite Sequence(水题)

    题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...

  6. 【arc071f】Infinite Sequence(动态规划)

    [arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...

  7. A - Infinite Sequence

    Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2,  ...

  8. Codeforces 601B. Lipshitz Sequence(单调栈)

    Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...

  9. 【CodeForces 622A】Infinite Sequence

    题意 一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字. 分析 第n个位置属于1到k,求出k,然后n-i*(i-1)/ ...

随机推荐

  1. 详谈 Jquery Ajax 异步处理Json数据.

    啥叫异步,啥叫Ajax.咱不谈啥XMLHTTPRequest.通俗讲异步就是前台页面javascript能调用后台方法.这样就达到了无刷新.所谓的Ajax.这里我们讲二种方法 方法一:(微软有自带Aj ...

  2. 使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务

    使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务 作者:Nikolay Manchev 分步构建一个跨这些平台的 ...

  3. Android Studio上的几个插件

    转载:http://blog.csdn.net/maosidiaoxian/article/details/44992655 以下所有插件都可以在Idea的插件库中找到,如果你与我一样在Android ...

  4. bzoj1312

    忘写题解了,经典的最大密度子图 可以类似分数规划的做,二分密度,然后转化为最大权闭合子图做,判断是否大于0 注意方案的输出 const eps=1e-6; lim=1e-12; inf=; type ...

  5. 好用的工具之一 ---- Sublime Text

    官网地址和详细解释:http://www.sublimetext.com/ 异次元的一些更详细的个人体验细节:http://www.iplaysoft.com/sublimetext.html

  6. UVa 12096 The SetStack Computer【STL】

    题意:给出一个空的栈,支持集合的操作,求每次操作后,栈顶集合的元素个数 从紫书给的例子 A={{},{{}}} B={{},{{{}}}} A是栈顶元素,A是一个集合,同时作为一个集合的A,它自身里面 ...

  7. Go2Shell 打开设置窗口

    Go2Shell默认没有设置界面,需要用命令行打开 在Shell中输入: open -a Go2Shell --args config

  8. linux下打开chm文件的方法

    windows中,通常情况下,chm文件可以使用系统自带的程序打开,但是linux就没有那么幸运了,那么,如何在linux下打开chm 文件呢?有小编来为您介绍介绍,本篇,小编以ubuntu环境为例 ...

  9. 【转】错误日志ID8021来源BROWSER导致电脑死机

    现场工控机死机,网上查了篇文章,具体原因还有待分析,下面是图 在这里有必要介绍两个ID号:6006和6005.在事件查看器里ID号为6006的事件表示事件日志服务已停止,如果你没有在当天的事件查看器中 ...

  10. OpenGL开发时,fatal error C1083: 无法打开包括文件:“gl\glut.h”: No such file or directory

    本人使用的是vs2012,编写一个简单的opengl程序,运行的时候总是提示: fatal error C1083: 无法打开包括文件:“gl/glut.h”: No such file or dir ...