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; } }