#P2155. Counting Genuine Banknotes in Monopoly Country

    ID: 15436 Type: Default 1000ms 256MiB

Counting Genuine Banknotes in Monopoly Country

Counting Genuine Banknotes in Monopoly Country

In Monopoly Country, due to rampant inflation and the proliferation of counterfeit money, the government has introduced a new policy. All banknotes are issued with serial numbers that are the factorials of integers from $1$ to $N$, i.e. $1!, 2!, \dots, N!$. However, only the banknotes with serial numbers that are coprime with $M!$ are considered genuine.

Princess Sala, the country’s leading real estate magnate, wishes to predict the total number of genuine banknotes available. Your task is to help her determine this number. Since the number can be very large, output the result modulo $R$.

Note: The factorial of an integer $x$ is denoted by $x!$.

inputFormat

The input consists of a single line containing three space-separated integers: $N$, $M$, and $R$.

outputFormat

Output a single integer representing the number of genuine banknotes modulo $R$.

sample

5 1 7
5