#P8928. Sum of Modular Products

    ID: 22092 Type: Default 1000ms 256MiB

Sum of Modular Products

Sum of Modular Products

Given three integers n, m, and p, compute the value of the following expression:

\( \sum_{i=1}^{n} \sum_{j=1}^{m} \left(i \times j \bmod p\right) \)

Here, \(i \times j \bmod p\) denotes the remainder when \(i \times j\) is divided by \(p\).

inputFormat

The input consists of a single line containing three space-separated integers: n, m, and p.

outputFormat

Output a single integer which is the result of the summation.

sample

1 1 2
1