标签:style blog color sp div log bs amp as
辗转相除法:求gcd(a,b)
扩展欧几里得:解关于x和y的方程:a*x+b*y=gcd(a,b)
1 int gcd(int a,int b){ 2 if (b==0) return a; 3 return gcd(b,a%b); 4 } 5 6 7 ------------------------------------------------ 8 9 10 int extgcd(int a,int b,int& x,int& y){ 11 int d=a; 12 if (b!=0){ 13 d=extgcd(b,a%b,y,x); 14 y-=(a/b)*x; 15 }else{ 16 x=1;y=0; 17 } 18 return d; 19 }
标签:style blog color sp div log bs amp as
原文地址:http://www.cnblogs.com/pdev/p/4065912.html