Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

최대공약수와 최소공배수 본문

Algorithm/Cases-BOJ

최대공약수와 최소공배수

Xi_kor 2020. 6. 20. 15:51
#include <iostream>
using namespace std;

int main() {
  
  //유클리드호제법
  int a, b;
  cin>>a>>b;
  int GCD,LCM;
  int A=a;
  int B=b;
  
  while(1)
  {
    int r=a%b;
    
    if(r==0){
      GCD=b;
      break;
    }
    
    a=b;
    b=r;
  }
  
  LCM=A/GCD*B/GCD*GCD;
  
  cout<<GCD<<" "<<LCM;

  return 0;
}

'Algorithm > Cases-BOJ' 카테고리의 다른 글

chebyshevtheo  (1) 2020.07.05
beehive  (0) 2020.07.03
약수 구하기 구현  (0) 2020.06.20
소인수분해 구현  (0) 2020.06.20
선택정렬의 구현  (0) 2020.06.20