#P6825. 「EZEC-4」求和
「EZEC-4」求和
Description
Given the value of a positive integer , compute the value of the following expression:
$$\displaystyle\sum_{i = 1}^n \sum_{j = 1}^n \gcd(i,j)^{i + j}$$Since the result may be very large, you only need to output the value modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer , representing the number of test cases.
For each test case:
One line contains two positive integers .
Output Format
For each test case, output one line with a positive integer, representing the required value.
2
2 1000000007
3 998244353
19
752
2
4 998244353
123456 1000000007
66420
3252328
Hint
This problem enables O2 optimization and bundled tests.
To eliminate incorrect solutions, the Constraints are intentionally set larger. Please pay attention to the impact of constant factors on your program.
Sample Explanation
Sample #1
For the first test case: $\operatorname{ans} = \gcd(1, 1)^2 + \gcd(1, 2)^3 + \gcd(2, 1)^3 + \gcd(2, 2)^4 = 1^2 + 1^3 + 1^3 + 2^4 = 3 + 16 = 19$. Therefore, the answer is .
Constraints
| Subtask | Score | Time Limit | |
|---|---|---|---|
| No special constraints |
For of the testdata, , and is prime, .
Translated by ChatGPT 5
京公网安备 11011102002149号