不定方程(Exgcd)

 1 #include<cstdio>
 2 using namespace std;
 3 int x,y;
 4 inline int abs(int a){return a>0?a:-a;}
 5 int exgcd(int a,int b){
 6     if(!b){x=1,y=0;return a;}
 7     int d=exgcd(b,a%b),t=x;
 8     x=y,y=t-(a/b)*y;
 9     return d;
10 }
11 int main(){
12     int a,b;
13     scanf("%d%d",&a,&b);
14     int d=exgcd(a,b);
15     if(c%d==0){
16         x*=c/d,t=abs(b/d);
17         x=(x%t+t)%t;
18         printf("%d",x);
19     }
20     return 0;
21 }
AC Code

 


参考文献:https://www.cnblogs.com/bztMinamoto/p/9321594.html

posted @ 2018-08-18 17:31  Rising_Date  阅读(322)  评论(0编辑  收藏  举报