最大公约数和最小公倍数.c 410 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. int gcd(int a, int b) {
  3. if (b == 0) {
  4. return a;
  5. }
  6. return gcd(b, a % b);
  7. }
  8. int lcm(int a, int b) {
  9. return a / gcd(a, b) * b;
  10. }
  11. int main() {
  12. int a, b;
  13. scanf("%d %d", &a, &b);
  14. int greatest_common_divisor = gcd(a, b);
  15. int least_common_multiple = lcm(a, b);
  16. printf("%d %d\n", greatest_common_divisor, least_common_multiple);
  17. return 0;
  18. }