算法导论-数论
算法递归定理 gcd(a,b)=gcd(a,a mod b)
gcd(a,0) = |a|
代码:
#include <stdio.h>int gcd(int a,int b){if(b == 0){return a;}return gcd(b,a%b);
}int main() {int a,b;while(1){scanf("%d %d",&a,&b);printf("%d",gcd(a,b));}return 0;
}
算法导论-数论
算法递归定理 gcd(a,b)=gcd(a,a mod b)
gcd(a,0) = |a|
代码:
#include <stdio.h>int gcd(int a,int b){if(b == 0){return a;}return gcd(b,a%b);
}int main() {int a,b;while(1){scanf("%d %d",&a,&b);printf("%d",gcd(a,b));}return 0;
}