일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array 객체
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey🌳😊
JavaScript: Greatest Common Divisor (최대 공약수), Least Common Multiple (최소 공배수) 본문
JavaScript: Greatest Common Divisor (최대 공약수), Least Common Multiple (최소 공배수)
yjyuwisely 2023. 6. 29. 15:39정수론 (1) - 최대공약수, 최소공배수, 유클리드 호제법
안녕하세요, Dimen입니다! 오늘부터 정수론에 대한 글을 써보고자 합니다. 정수론은 정규 수학 교육과정에서 잘 다루지 않기 때문에 많은 분들에게 생소한 분야입니다. 그런 만큼 많은 분들에게
dimenchoi.tistory.com
Greatest Common Divisor (최대 공약수)
:the greatest common divisor of two or more integers is the largest positive integer that divides each of the given integers without leaving a remainder.
function GCD(x, y) {
return !x ? y : GCD(y, x % y);
}
!b: to check if the value of b is equal to 0. (! = (logical NOT))
If it is, the function returns a as the greatest common divisor.
If b is not equal to 0, the function calls itself recursively, passing b as the new value of a and the remainder of a divided by b (a % b) as the new value of b.
This process continues until b becomes 0, at which point the function returns a as the greatest common divisor.
Least Common Multiple (최소 공배수)
The GCD represents the largest positive integer that divides both x and y without leaving a remainder.
function LCM(x, y) {
return (x * y) / GCD(x, y);
}
1. The GCD(x, y) function is called to calculate the GCD of x and y.
2. The product of x and y is divided by the GCD using the division operator /.
3. The result is the LCM of x and y.
'💻Bootcamp Self-Study Revision✨ > JavaScript, jQuery, Ajax' 카테고리의 다른 글
Differences between Spring/JSP and React/TypeScript for CRUD Operations (0) | 2023.07.31 |
---|---|
The pros and cons of using Axios and Fetch API (0) | 2023.07.31 |
JavaScript: padStart, padEnd, map() (0) | 2023.06.28 |
JavaScript: 바코드 Generator에서 QR코드로 물품 이름 읽기 (0) | 2023.06.27 |