#P3811. 【模板】模意义下的乘法逆元

    ID: 4532 远端评测题 500ms 125MiB 尝试: 12 已通过: 9 显示难度普及 上传者: 标签>数学递推O2优化素数判断,质数,筛法逆元

【模板】模意义下的乘法逆元

Background

This is a template problem.

Problem Description

Given positive integers n,pn, p, find the multiplicative inverses modulo pp for all integers in [1,n][1, n].

The multiplicative inverse of aa modulo pp is defined as the solution xx to ax≡1(modp)ax\equiv1\pmod p.

Input Format

One line with two positive integers n,pn, p.

Output Format

Output nn lines, where the ii-th line denotes the multiplicative inverse of ii modulo pp.

10 13
1
7
9
10
8
11
2
5
3
4

Hint

All testdata satisfy 1≤n≤3×106 1 \leq n \leq 3 \times 10 ^ 6, n<p<20000528n < p < 20000528 . The input guarantees that p p is prime.

Translated by ChatGPT 5