#P1082. [NOIP 2012 提高组] 同余方程

    ID: 82 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学2012NOIp 提高组扩展欧几里德,扩欧

[NOIP 2012 提高组] 同余方程

Description

Find the smallest positive integer solution of x x to the congruence equation ax1(modb) a x \equiv 1 \pmod {b}.

Input Format

One line containing two integers a,ba,b, separated by a single space.

Output Format

A single integer x0x_0, which is the smallest positive solution. The input is guaranteed to have a solution.

3 10
7

Hint

Constraints

  • For 40%40\% of the testdata, 2b1,0002 \le b \le 1{,}000.
  • For 60%60\% of the testdata, 2b50,000,0002 \le b \le 50{,}000{,}000.
  • For 100%100\% of the testdata, 2a,b2,000,000,0002 \le a, b \le 2{,}000{,}000{,}000.

Translated by ChatGPT 5