1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int a,b; 6 while(~scanf("%d%d",&a,&b)) 7 { 8 int m=a*b; 9 int p,q,r; 10 p=a>b?a:b; 11 q=a<b?a:b; 12 r=p%q; 13 while(r!=0) 14 { 15 p=q; 16 q=r; 17 r=p%q; 18 } 19 printf("%d ",m/q); 20 } 21 }
最后最小公倍数m/q的q就是最大公约数。