Title Description
The minimum positive integer solution for the congruence equation ax≡1 (mod b) of x is obtained.
Input/output format
Input format:
Enter only one row, containing two positive integers a, b, separated by a space.
Output format:
The output has only one row and contains a positive integer x0, which is the minimum positive integer solution. The input data guarantees that there must be a solution.
Input and Output Sample input example # #:
3 10
Sample # # of output:
7
Description
"Data Range"
For 40% of data, 2≤b≤1,000;
For 60% of data, 2≤b≤50,000,000;
For 100% of data, 2≤a, b≤2,000,000,000.
NOIP 2012 Raising group The first question of the second day
Basic application of Extended Euclidean algorithm
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cmath>5 using namespacestd;6 intb;7 voidEXGCD (intAintBint&x,int&y) {8 if(b==0){9x=1; y=0;Ten return; One } AEXGCD (b,a%b,x,y); - intt=x;x=y;y=t-a/b*y; - } the intMain () { -scanf"%d%d",&a,&b); - intx, y; - EXGCD (a,b,x,y); +x= (x%b+b)%b; -printf"%d\n", x); + return 0; A}
Rokua P1082 congruence equation