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

    ID: 7839 Type: RemoteJudge 500ms 125MiB Tried: 87 Accepted: 16 Difficulty: 5 Uploaded By: Tags>数论数学素数判断质数筛法逆元递推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 ax1(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 1n3×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