Educational Codeforces Round 7 A

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 7 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 test(s)
input
3
output
2
input
5
output
2
input
10
output
4
input
55
output
10
input
56
output
1
没什么好说的,先是一个等差数列求和,然后判断一下就行,如果等于一个和,说明一个循环结束,不是就减去
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int t;
int n,m;
int sum,ans,flag;
int a,b,c,d;
int main()
{
    LL n;
    LL b;
    LL ans;
    LL i=0;
    LL sum=0;
    cin>>n;
    while(sum<=n)
    {
        i++;
        sum=1*i+(i)*(i-1)/2;
       // i++;
    }
   // cout<<i-1<<endl;
    ans=i-1;
   // cout<<1*ans+(ans)*(ans-1)/2<<endl;
    b=1*ans+(ans)*(ans-1)/2;
    if(n==1*ans+(ans)*(ans-1)/2)
    {
        cout<<ans<<endl;
    }
    else
    {
        cout<<n-b<<endl;
    }
    return 0;
}

  

 

以上是关于Educational Codeforces Round 7 A的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27