본문으로 바로가기
#include <cstdio>

int gcd (int, int);// Greatest Common Divisor
int lcm (int, int);// Least Common Multiple

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  printf("GCD: %d, LCM: %d\n", gcd(x, y), lcm(x, y));
}

int gcd (int x, int y) {
  return (x%y) == 0 ? y : gcd(y, x%y);
}
int lcm (int x, int y){
  return (x*y) / gcd(x, y);
}

댓글을 달아 주세요