QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#16538. Gcd with Xor

الإحصائيات

ねえ もしも全て投げ捨てられたら / Hey, if I could throw everything away,

笑って生きることが楽になるの / would it become easier to live with a smile?

Given two positive integers $n$ and $k$.

Define $\displaystyle f(x)=\sum_{i=1}^x \gcd(i,i\oplus x)^k$. Calculate $\displaystyle \sum_{i=1}^n f(i)$, where $\gcd(a,b)$ denotes the greatest common divisor of $a$ and $b$, and $\oplus$ denotes the bitwise XOR operation (the ^ operator in C++).

Since the answer may be very large, output the result modulo $10^9+7$.

Input

This problem contains multiple test cases.

The first line contains an integer $T$, representing the number of test cases.

Each test case consists of a single line containing two positive integers $n$ and $k$.

Output

For each test case, output a single integer representing the answer modulo $10^9+7$.

Examples

Input 1

5
3 2
10 1
261 261
2333 2333
124218 998244353

Output 1

17
134
28873779
470507314
428587718

Note 1

For the first test case:

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

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

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

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

Constraints

For all test cases, $1\le T\le 1000$, $1\le n\le 2\times 10^5$, $\sum n\le 2\times 10^5$, $1\le k\le 10^9$.

This problem uses bundled testing.

Let $\sum n$ denote the sum of $n$ in a single test case.

  • Subtask 1 (10 points): $\sum n\le 2000$.
  • Subtask 2 (12 points): $\sum n\le 10^4$.
  • Subtask 3 (15 points): $k=1$.
  • Subtask 4 (45 points): $\sum n\le 10^5$.
  • Subtask 5 (18 points): No additional constraints.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.