模板,,,
#include<cstdio> using namespace std; void exgcd(long long a,long long b,long long &x,long long &y){ if (b==0) {x=1; y=0;} else {exgcd(b,a%b,x,y); int t=y; y=x-a/b*y; x=t;} } int main(){ long long a,b,x,y; scanf("%lld %lld\n",&a,&b); exgcd(a,b,x,y); printf("%lld\n",(x+b)%b); return 0; }
时间: 2024-12-13 06:57:56