time limit: 1 sspace limit: 128000 KBDescription of the problem
Description
The minimum positive integer solution for ax≡1 (mod b) of the x congruence equation is obtained.
Enter a description
Input Description
Enter only one row, containing two positive integers a, b, separated by a space.
Output description
Output Description
The output has only one row containing a positive integer x0, or a minimum positive integer solution, and the input data guarantees there must be a solution.
Sample input
Sample Input
3 10
Sample output
Sample Output
7
Data range and Tips
Data Size & Hint
"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
Expansion of the Euclid algorithm.
The code is actually:
#include <cstdio>
void gcd (int x,int y,int &a,int &b,int &c) {
if (!y) {A=x;b=1;c=0;return;}
GCD (Y,X%Y,A,C,B);
C-=x/y*b;
}
int main () {
int n,k,a,b,c;
scanf ("%d%d", &n,&k);
GCD (N,K,A,B,C);
b= (b%k+k)%k;
printf ("%d", b);
return 0;
}
Congruence Equation 2012 Noip National League Improvement Group