参考资料:Arimura | kasumi int gcd(int a, int b){ return b==0?a:gcd(b, a%b); } void exgcd(int a, int b, int &x, int &y){ if(b==0){ x = 1; y = 0; return; } exgcd(b, a%b, x, y); int tmp = x; x = y; y = tmp-a/b*y; }