给定一个素数 $p$ 和一个整数 $a$,请计算 $a$ 模 $p$ 的乘法逆元。
若 $a$ 不是 $p$ 的倍数,则存在唯一的整数 $x$ 满足 $0 < x < p$ 且 $ax \equiv 1 \pmod{p}$,称 $x$ 为 $a$ 模 $p$ 的乘法逆元。
输入格式
输入包含两个整数 $a$ 和 $p$。
输出格式
输出 $a$ 模 $p$ 的乘法逆元。
样例
输入格式 1
3 7
输出格式 1
5
说明
题目保证 $p$ 是素数。
给定一个素数 $p$ 和一个整数 $a$,请计算 $a$ 模 $p$ 的乘法逆元。
若 $a$ 不是 $p$ 的倍数,则存在唯一的整数 $x$ 满足 $0 < x < p$ 且 $ax \equiv 1 \pmod{p}$,称 $x$ 为 $a$ 模 $p$ 的乘法逆元。
输入包含两个整数 $a$ 和 $p$。
输出 $a$ 模 $p$ 的乘法逆元。
3 7
5
题目保证 $p$ 是素数。
| ID | Type | Status | Title | Posted By | Last Updated | Actions |
|---|---|---|---|---|---|---|
| Editorial | Open | Official Editorial | Qingyu | - | Download |
The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.
This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.
If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.
Guidelines: