1012 【模板】同余方程
作者:互联网
分析
模板题
#include<bits/stdc++.h> using namespace std; #define int long long int gcd_ex(int a,int b,int &x,int &y) { if(b == 0) {x = 1,y = 0;return a;} int d = gcd_ex(b,a%b,y,x); y = y - (a / b) * x; return d; } signed main() { int t;cin>>t;while(t -- ) { int x,y; int a,b;cin>>a>>b; int d = gcd_ex(a,b,x,y); x = (x % b + b) % b; if(d == 1) cout<<x<<endl; else cout<<-1<<endl; } }
标签:return,gcd,int,cin,long,1012,ex,模板,同余 来源: https://www.cnblogs.com/er007/p/16519448.html