QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100

#15001. Kth 1

統計

We are given a 64-bit unsigned integer x. Number its binary bits from least significant to most significant as positions 0, 1, 2, ..., 63.

For a given positive integer k, we define the answer for the pair (x, k) as follows:

  • If, in the binary representation of x, there exists a k-th 1 bit when scanning from least significant bit to most significant bit, then the answer is the position of that 1 bit;
  • Otherwise (if x has fewer than k bits set to 1), the answer is 64.

You must generate many pairs (x, k) according to the given rules, compute the answer for each pair, and output the sum of all answers.

Input

The input consists of two integers: the number of queries $n$ and the pseudo-random seed $seed$. You must generate all queries from the seed. The generation process is given in the reference code below.

Output

Output a single non-negative integer: the sum of the answers over all $n$ queries.

Sample

Input

2048 60576

Output

100000

Reference Code

You may base your solution on the following code; you only need to complete the query function. You are also allowed to modify the code in any way if you wish.

#include <iostream>
int n;
using u64 = unsigned long long;
u64 seed, ans = 0;

u64 next(u64 &x) {
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    return x;
}

int query(u64 x, int k) {
    // TODO: implement this function
}

int main() {
    std::cin >> n >> seed;
    for (int i = 0; i < n; ++i) {
        u64 x = next(seed);
        int k = (next(seed) & 63) + 1;
        ans += query(x, k);
    }
    std::cout << ans << '\n';
}

Subtasks

  • Subtask 1 (0 points): $1 \le n \le 10^5$
  • Subtask 2 (1 point): $1 \le n \le 10^8$
  • Subtask 3 (7 points): $1 \le n \le 2\times 10^8$
  • Subtask 4 (8 points): $1 \le n \le 3\times 10^8$
  • Subtask 5 (9 points): $1 \le n \le 4\times 10^8$
  • Subtask 6 (10 points): $1 \le n \le 5\times 10^8$
  • Subtask 7 (11 points): $1 \le n \le 6\times 10^8$
  • Subtask 8 (12 points): $1 \le n \le 7\times 10^8$
  • Subtask 9 (13 points): $1 \le n \le 8\times 10^8$
  • Subtask 10 (14 points): $1 \le n \le 9\times 10^8$
  • Subtask 11 (15 points): $1 \le n \le 10^9$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.