Topic Portal
Problem-solving ideas:
Because the derivation process is too complicated, too lazy to write, so the solution to a problem Portal
AC Code:
1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 long long a,b,x,y; 7 8 void exgcd(long long p,long long o) { 9 if(o == 0) { 10 x = 1; 11 y = 0; 12 return ; 13 } 14 exgcd(o,p % o); 15 long long tx = x; 16 x = y; 17 y = tx - p / o * y; 18 } 19 20 int main() { 21 cin >> a >> b; 22 exgcd(a,b); 23 x = (x % b + b) % b; 24 printf("%lld",x); 25 return 0; 26 }