CodeForces 622A Infinite Sequence

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 622A Infinite Sequence相关的知识,希望对你有一定的参考价值。

简单题,公式打了个表,查询的时候二分一下就行。也可以直接o(1)公式出解。

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std;

long long a[20000005];

int main()
{
    for (int i = 1; i <= 20000000; i++)
    {
        long long now = (long long)i;
        a[i] = (1 + now)*now / 2;
    }

    long long n;
    while (~scanf("%lld", &n)){

        int l = 1, r = 20000000;
        int pos;
        while (l <= r)
        {
            int mid = (l + r) / 2;
            if (a[mid] <= n) { pos = mid; l = mid + 1; }
            else r = mid - 1;
        }

        if (a[pos] == n) printf("%d\n", pos);
        else printf("%lld\n", n - a[pos]);
    }
    return 0;
}

 

以上是关于CodeForces 622A Infinite Sequence的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #353 (Div. 2) A. Infinite Sequence 思维题

Infinite Prefixes CodeForces - 1295B

[CodeForces - 197D] D - Infinite Maze

Codeforces 1295B - Infinite Prefixes

Codeforces Round #301 (Div. 2) E. Infinite Inversions —— 逆序对 离散化 + 树状数组

Codeforces 1295B Infinite Prefixes