#P10855. 【MX-X2-T4】「Cfz Round 4」Gcd with Xor

    ID: 12325 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学数论O2优化莫比乌斯反演容斥原理字典树 Trie梦熊比赛

【MX-X2-T4】「Cfz Round 4」Gcd with Xor

Background

Original link: https://oier.team/problems/X2D


Hey, if we could throw everything away,
Hey, if we could throw everything away.

Would living with a smile become easier?
Would living with a smile become easier?

Problem Description

Given two positive integers n,kn, k

Define $\displaystyle f(x)=\sum_{i=1}^x \gcd(i,i\oplus x)^k$。Compute i=1nf(i)\displaystyle \sum_{i=1}^n f(i)。Here, gcd(a,b)\gcd(a,b) denotes the greatest common divisor of aa and bb, and \oplus denotes bitwise XOR, i.e. ^ in C++。

Since the answer may be very large, you only need to output the result modulo 109+710^9+7

Input Format

This problem has multiple test cases.

The first line contains an integer TT, indicating the number of test cases.

Then each test case follows. For each test case, input one line with two positive integers n,kn, k

Output Format

For each test case, output one line with one integer, representing the answer modulo 109+710^9+7

5
3 2
10 1
261 261
2333 2333
124218 998244353
17
134
28873779
470507314
428587718

Hint

[Sample Explanation]

For the 11-st test case:

f(1)=gcd(1,0)2=1f(1)=\gcd(1,0)^2=1

f(2)=gcd(1,3)2+gcd(2,0)2=5f(2)=\gcd(1,3)^2+\gcd(2,0)^2=5

f(3)=gcd(1,2)2+gcd(2,1)2+gcd(3,0)2=11f(3)=\gcd(1,2)^2+\gcd(2,1)^2+\gcd(3,0)^2=11

f(1)+f(2)+f(3)=17f(1)+f(2)+f(3)=17

[Constraints]

For all test cases, 1T10001\le T\le 1000, 1n2×1051\le n\le 2\times 10^5, n2×105\sum n\le 2\times 10^5, 1k1091\le k\le 10^9

This problem uses bundled testdata.

Let n\sum n denote the sum of nn within a single test point.

  • Subtask 1 (10 points): n2000\sum n\le 2000
  • Subtask 2 (12 points): n104\sum n\le 10^4
  • Subtask 3 (15 points): k=1k=1
  • Subtask 4 (45 points): n105\sum n\le 10^5
  • Subtask 5 (18 points): no special constraints。

Translated by ChatGPT 5