#P3811. Modular Multiplicative Inverses

    ID: 17061 Type: Default 1000ms 256MiB

Modular Multiplicative Inverses

Modular Multiplicative Inverses

Given two integers n and p (with p being a prime number), compute the modular multiplicative inverse of every integer in the range from 1 to n modulo p.

The modular multiplicative inverse of an integer a modulo p is defined as the integer x which satisfies the equation $$a \times x \equiv 1 \pmod{p}.$$

You may assume that a modular inverse exists for every integer from 1 to n under the given prime modulus p (by Fermat's Little Theorem). Use it to compute the answer.

inputFormat

The input consists of a single line containing two space-separated integers n and p, where p is a prime number.

Constraints: 1 ≤ n < p.

outputFormat

Output a single line containing n space-separated integers. The i-th integer should be the modular multiplicative inverse of i modulo p.

sample

5 7
1 4 5 2 3