#P3768. Summation of Weighted GCD Products Modulo p

    ID: 17018 Type: Default 1000ms 256MiB

Summation of Weighted GCD Products Modulo p

Summation of Weighted GCD Products Modulo p

This problem requires you to compute the following expression:

$$\left(\sum_{i=1}^n\sum_{j=1}^n ij\,\gcd(i,j)\right) \bmod p$$

where \(\gcd(a,b)\) denotes the greatest common divisor of \(a\) and \(b\). The input consists of two integers, \(n\) and \(p\), where \(n\) defines the range for the summation and \(p\) is the modulus.

Your task is to output the computed result.

inputFormat

The input consists of a single line containing two integers \(n\) and \(p\) separated by a space.

outputFormat

Output a single integer: the value of \(\left(\sum_{i=1}^n\sum_{j=1}^n ij\,\gcd(i,j)\right) \bmod p\).

sample

1 100
1