File size: 673 Bytes
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# P3811 — Multiplicative Inverses Modulo a Prime

## Description

Given positive integers $n$ and $p$, find the multiplicative inverse modulo
$p$ of every integer in $[1,n]$.

An integer $x$ is a multiplicative inverse of $a$ modulo $p$ if

$$
ax \equiv 1 \pmod p.
$$

The input guarantees that $p$ is prime.

## Input

The only line contains two positive integers $n$ and $p$.

## Output

Print $n$ lines. The $i$-th line contains the multiplicative inverse of $i$
modulo $p$.

## Constraints

- $1 \le n \le 3\times10^6$.
- $n < p < 20000528$.
- $p$ is prime.

## Source

[Luogu P3811, "Multiplicative Inverses Modulo a Prime"](https://www.luogu.com.cn/problem/P3811).