0
点赞
收藏
分享

微信扫一扫

CodeForces - 622A Infinite Sequence (思想)水

Time Limit: 1000MS

 

Memory Limit: 262144KB

 

64bit IO Format: %I64d & %I64u

CodeForces - 622A


Infinite Sequence



Submit Status




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 1to 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

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 thelong long integer type and in Java you can use long






Output




Print the element in the n-th position of the sequence (the elements are numerated from one).






Sample Input





Input



3





Output



2





Input



5





Output



2





Input



10





Output



4





Input



55





Output



10





Input



56





Output



1





Source



Educational Codeforces Round 7



//题意:



给出如上的数列,输入一个n,问在这个数列上第n个位置上的数是啥。



//思路:直接模拟就行了,没啥技巧




#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define IN __int64
#define ll long long
#define N 10010
#define M 1000000007
#define PI acos(-1.0)
using namespace std;
int main()
{
	int i,j,k;
	IN n;
	while(scanf("%I64d",&n)!=EOF)
	{
		ll k=1;
		while(n>k)
		{
			n-=k;
			k++;
		}
		printf("%I64d\n",n);
	}
	return 0;
}




举报

相关推荐

0 条评论