#include<stdio.h> int main() { int p,q,m,n; scanf("%d%d", &p, &q); m=p; n=q; while(m!=n)//当两者不相等时,采用相减法求最大公约数 { if(m>n) m=m-n; else n=n-m; } printf("%d %d\n",p*q/m,m); }
Double click to view unformatted code.