Wikioi 1200 Congruence equation
Title Description
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
Idea: Seek inverse meta code:
1#include <cstdio>2 #definell Long Long3 4 5 6 voidEXGCD (ll a,ll b,ll &x,ll &y)7 {8 if(b==0)9 {Tenx=1; y=0;return; One } AEXGCD (b,a%b,x,y); -ll t=x; -x=y; theY=t-(A/b) *y; - } - - + intMain () - { +ll A,B;SCANF ("%lld%lld",&a,&b); A ll x, y; at EXGCD (a,b,x,y); -printf"%lld", (x+b)%b); - return 0; -}
View Code
Mathematics--modulo arithmetic