标签:com 纯粹 str html ane 难度 out turn bsp
输入2个数M, N中间用空格分隔(1 <= M < N <= 10^9)
输出一个数K,满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的。
2 3
2
纯粹的求逆元
1 #include <iostream> 2 3 using namespace std; 4 5 int exgcd(int a,int b,int &x,int &y){ 6 if(b==0){ 7 x=1,y=0; 8 return a; 9 } 10 int r = exgcd(b,a%b,x,y); 11 int t = x; 12 x = y; 13 y = t-(a/b)*y; 14 return r; 15 } 16 int main(){ 17 int n,m; 18 cin>>n>>m; 19 int x,y; 20 int p = exgcd(n,m,x,y); 21 cout<<(x+m)%m<<endl; 22 return 0; 23 }
标签:com 纯粹 str html ane 难度 out turn bsp
原文地址:https://www.cnblogs.com/zllwxm123/p/8922059.html