#P10322. 高洁(Purity)
高洁(Purity)
Background
Simple, accurate, and everlasting beauty — Purity.
“Light of Purity” Ram, as the Elf King, can perfectly use the power of The Ames Grass Paper Book.
Problem Description
Ram uses “Storm Arrow Rain” and shoots arrows at once. The original attack power of the -th arrow is . However, these arrows will receive some enhancements.
For a constant , define the energy level of an arrow with original attack power as :
- If there does not exist a positive integer such that is a multiple of , then ;
- Otherwise, is the smallest positive integer such that is a multiple of .
Then the enhanced attack power of this arrow is .
Ram wants to know the sum of the attack powers of all arrows after enhancement. Since the answer may be very large, you only need to output the result modulo (that is, the remainder when dividing the answer by ).
Input Format
The first line contains a positive integer , the number of test cases.
The next lines each contain two positive integers , with meanings as described above.
Output Format
Output lines, each line containing the answer for one test case.
5
15 12
400 2520
5000000 68256
10000000 65536
10000000000 3628800
462
946645637
231125775
290821843
602104955
Hint
[Sample Explanation]
For the first test case, . Here because divides but does not divide . Similarly, we have .
It can be seen that all other numbers up to have energy level , so the answer is:
For the second test case, it can be proved that within only is non-zero. From this, the answer is , and after taking modulo it becomes .
[Constraints]
This problem uses bundled tests.
Subtask 1 (15 pts): ;
Subtask 2 (15 pts): is prime;
Subtask 3 (20 pts): is a positive integer power of a prime;
Subtask 4 (20 pts): there does not exist an integer such that divides ;
Subtask 5 (30 pts): no special restrictions.
For all data, , , .
[Hint]
The time limit for this problem is relatively generous. Even if your code is not optimized in some details, it can still pass normally.
Translated by ChatGPT 5