#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int gcd(int a,int b)
{
int m;
if((m=a%b)==0) return b;
return gcd(b,m);
}
int main(int argc,char *argv[])
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",gcd(a,b));
return 0;
}
2.最小公倍数(用最大公约数实现)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int gcd(int a,int b)
{
int m;
if((m=a%b)==0) return b;
return gcd(b,m);
}
static int lcm(int a,int b)
{
int gcd_value=gcd(a,b);
return a*b/gcd_value;
}
int main(int argc,char *argv[])
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",lcm(a,b));
return 0;
}