#P10322. 高洁(Purity)

    ID: 11493 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学数论洛谷原创O2优化莫比乌斯反演拉格朗日插值法洛谷比赛

高洁(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 nn arrows at once. The original attack power of the ii-th arrow is ii. However, these arrows will receive some enhancements.

For a constant dd, define the energy level of an arrow with original attack power ii as v(i)v(i):

  • If there does not exist a positive integer kk such that iki^k is a multiple of dd, then v(i)=0v(i)=0;
  • Otherwise, v(i)v(i) is the smallest positive integer kk such that iki^k is a multiple of dd.

Then the enhanced attack power of this arrow is iv(i)+1i^{v(i)+1}.

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 998244353998244353 (that is, the remainder when dividing the answer by 998244353998244353).

Input Format

The first line contains a positive integer TT, the number of test cases.
The next TT lines each contain two positive integers n,dn,d, with meanings as described above.

Output Format

Output TT 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, d=12d=12. Here v(6)=2v(6)=2 because 1212 divides 626^2 but does not divide 616^1. Similarly, we have v(12)=1v(12)=1.
It can be seen that all other numbers up to n=15n=15 have energy level 00, so the answer is:

(i=115i)612+63+122=462\left(\sum_{i=1}^{15}i\right)-6-12+6^3+12^2=462

For the second test case, it can be proved that within nn only v(210)=3v(210)=3 is non-zero. From this, the answer is 19448899901944889990, and after taking modulo 998244353998244353 it becomes 946645637946645637.

[Constraints]
This problem uses bundled tests.

Subtask 1 (15 pts): 1n,d1041 \le n,d \le 10^4;
Subtask 2 (15 pts): dd is prime;
Subtask 3 (20 pts): dd is a positive integer power of a prime;
Subtask 4 (20 pts): there does not exist an integer x>1x>1 such that x4x^4 divides dd;
Subtask 5 (30 pts): no special restrictions.

For all data, 1T10001\le T \le 1000, 1n<2631\le n < 2^{63}, 1d1081\le d \le 10^8.

[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