2749: 3301 同余方程

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:1 Solved:0

Description

求关于 x的同余方程  ax ≡ 1(mod b) 的最小正整数解。

Input

输入只有一行,包含两个正整数a,b,用一个空格隔开。

Output

输出只有一行,包含一个正整数,包含一个正整数 ,包含一个正整数 x0,即最小正整数解。 输入数据保证一定有解。

Sample Input Copy

3 10

Sample Output Copy

7

HINT

数据范围与约定

  • 对于 40% 的数据    2 ≤b≤1,000
    对于 60% 的数据    2 ≤b≤50,000,000
    对于 100%的数据    2 ≤a, b≤2,000,000,000