标签:
输入2个数M, N中间用空格分隔(1 <= M < N <= 10^9)
输出一个数K,满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的。
2 3
2
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define ll long long 6 using namespace std; 7 ll x,y; 8 ll exgcd(ll a,ll b){ 9 if(b==0){ 10 x=1;y=0;return a; 11 } 12 int g=exgcd(b,a%b); 13 int t=x; 14 x=y; 15 y=t-a/b*y; 16 return g; 17 } 18 19 int main(){ 20 ll a,b,c; 21 scanf("%lld%lld",&a,&b); 22 int g=exgcd(a,b); 23 printf("%lld\n",(x%b+b)%b); 24 return 0; 25 }无话可说,QAQ
标签:
原文地址:http://www.cnblogs.com/radiumlrb/p/5929166.html