eolymp
Competitions

DSA Week 2

Sum of powers 2

Find the sum (11 + 22 + 33 + .... + nn) mod m.

Input

Two positive integers n and m (n, m106).

Output

Print the value of the sum modulo m.

Time limit 2 seconds
Memory limit 128 MiB
Input example #1
4 100
Output example #1
88
Author Michael Medvedev