-
최대 공약수, 공배수 구하기 // 코테기타 2023. 5. 11. 11:31
두 정수 a 와 b 가 있다
- 최대 공약수
유클리드 호제법에 따라
a와 b의 최대 공약수는 b와 a%b 의 최대 공약수와 같다 ( 단, a%b가 0이라면, b가 a와 b의 최대공약수가 된다. )
따라서
다음과 같은 형태로, a%b가 0이 될 때 까지 반복시키고 a를 구하면 최대 공약수를 구할 수 있다
- 최소 공배수
두 수의 곱에 최대 공약수를 나누면 최소 공배수를 구할 수 있다
최소 공배수 = a * b / gcd (a,b)
'기타' 카테고리의 다른 글
더미데이터 생성하기 ( Mockaroo ) (0) 2023.06.07 반응형 웹 레이아웃 만들기 (0) 2023.05.15 CSS - em , rem , vw , vh , % (0) 2023.04.28 JavaScript에서 생성자를 초기화하면 메소드들이 실행된다. (0) 2023.04.26 git pull 오류 ( Synchronize 가 맞지 않을 때 ) (0) 2023.04.19