最大公约数(greatest common divisor,简写为gcd;或highest common factor,简写为hcf),指某几个整数共有因子中最大的一个。
int gcd(int a,int b) { int r; if(a<0) a=-a; while(b!=0) { r=a%b; a=b; b=r; } return a; }
int gcd(int x,int y) { while(x!=y) { if(x>y) x-=y; else y-=x; } return x; }
posted on 2010-11-20 20:33 yming0221 阅读(143) 评论(0) 收藏 举报