#P10322. Enhanced Arrow Attack Sum

    ID: 12325 Type: Default 1000ms 256MiB

Enhanced Arrow Attack Sum

Enhanced Arrow Attack Sum

In this problem, Ram uses his "Storm Arrow Rain" to shoot n arrows. The initial attack power of the i-th arrow is i. However, before reaching the target, each arrow is enhanced according to a special rule.

For a given constant d, define the energy level \( v(i) \) of an arrow with initial attack i as follows:

  • If there does not exist any positive integer \( k \) such that \( i^k \) is divisible by \( d \), then \( v(i)=0 \).
  • If such a \( k \) exists, then \( v(i) \) is the smallest positive integer \( k \) such that \( i^k \) is divisible by \( d \).

The enhanced attack power of the arrow is then computed as \( i^{v(i)+1} \).
Ram would like to know the sum of the enhanced attack powers of all arrows from \( 1 \) to \( n \). Since the answer might be very large, output the result modulo 998244353.

Note: If for an arrow, no such \( k \) exists (i.e. at least one prime factor of \( d \) does not divide \( i \)), then by definition \( v(i)=0 \) and the final attack power is \( i^{0+1}=i \).

For clarity, observe that if \( d \) has the prime factorization \( d=\prod_{p}p^{e_p} \), then for an arrow with attack i, if for every prime \( p \) dividing \( d \) the number \( i \) is also divisible by \( p \) (say, with exponent \( a_p \) in \( i \)), the smallest positive integer \( k \) satisfying \( k\cdot a_p \ge e_p \) for all such primes is taken as \( v(i) \). Otherwise, \( v(i)=0 \) and the arrow remains unenhanced.

inputFormat

The input consists of a single line containing two space-separated integers n and d:

  • n — the number of arrows.
  • d — the constant used for determining the energy level.

outputFormat

Output a single integer — the sum of the enhanced attack powers of all arrows from \( 1 \) to \( n \), taken modulo 998244353.

sample

5 10
15