欧几里得扩张模板
public class f扩展欧几里得 {static long x;static long y;
public static void main(String[] args) { try {long f=linearEquation(3,9,6);System.out.println(f);System.out.println(x+" "+y);} catch (Exception e) {e.printStackTrace();}
}
private static long ext_gcd(long a, long b) {if(b==0) {x=1;y=0;return a;}long res=ext_gcd(b,a%b);long x1=x;x=y;y=x1-a/b*y;return res;
}
public static long linearEquation(long a,long b,long m)throws Exception {long d=ext_gcd(a, b);if(m%d!=0) {throw new Exception("无解");}long n=m/d;x*=n;y*=n;return d;
}
}