CodeForces 622 A. Infinite Sequence(水~)

Description
定义一个序列:1 1 2 1 2 3 1 2 3 4 5….问这个序列第n个数是多少
Input
一个整数n(1<=n<=10^14)
Output
输出这个序列的第n个数
Sample Input
55
Sample Output
10
Solution
简单题
Code

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll n;
int main()
{
    while(~scanf("%I64d",&n))
    {
        ll k=(1+sqrt(1+4*n))/2;
        while(k*(k-1)/2<n)k++;
        k--;
        printf("%I64d\n",n-k*(k-1)/2);
    }
    return 0;
}

你可能感兴趣的:(CodeForces 622 A. Infinite Sequence(水~))