-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function solution(n, m) { | ||
var answer = []; | ||
|
||
// 최대공약수 | ||
function getGreatestCommonDivisor(n, m) { | ||
let gcd = 1; | ||
for(let i = 2; i <= Math.min(n, m); i++) { | ||
if(n%i === 0 && m%i === 0) gcd = i; | ||
} | ||
return gcd; | ||
} | ||
|
||
// 최소공배수 | ||
function getLeastCommonMultiple(n, m) { | ||
let lcm = 1; | ||
while(1) { | ||
if((lcm%n === 0) && (lcm%m) === 0) { | ||
break; | ||
} | ||
lcm++; | ||
} | ||
return lcm; | ||
} | ||
|
||
let num1 = getGreatestCommonDivisor(n,m); | ||
let num2 = getLeastCommonMultiple(n,m); | ||
|
||
answer.push(num1); | ||
answer.push(num2); | ||
|
||
return answer; | ||
} | ||
|
||
console.log(solution(5, 10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
|
||
|
||
# List | ||
|번호|정답여부|풀이|개념| | ||
|:---:|:---:|:---:|:---:| | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
> 수학관련 내용 정리! | ||
# 두 수의 최대공약수 구하기 | ||
- 최대공약수는 num1, num2의 **공통된 약수** 중 **가장 큰 정수**를 의미함 | ||
- 2부터 Math.min(num1, num2)까지 모든 정수로 나눠보면 됨 | ||
|
||
## 코드 | ||
```js | ||
function getGreatestCommonDivisor(num1, num2) { | ||
let gcd = 1; | ||
for(let i = 2; i <= Math.min(num1, num2); i++) { | ||
if(num1%i === 0 && num2&i ===0) gcd = i; | ||
} | ||
return gcd; | ||
} | ||
|
||
getGreatestCommonDivisor(5, 10); | ||
``` | ||
|
||
## 풀이 | ||
<img src='./img/math_1.JPG' width="500px" alt="최대공약수" /> <br> | ||
|
||
|
||
# 두 수의 최소공배수 구하기 | ||
- 최소공배수는 num1과 num2의 **공통인 배수** 중 **가장 작은 수**를 의미함 | ||
- lcm을 1부터 시작하여 lcm++을 하면서 num1과 num2로 lcm으로 나눴을 때, 나머지 값이 0인지 확인해보기 | ||
|
||
## 코드 | ||
```js | ||
function getLeastCommonMultiple(num1, num2) { | ||
let lcm = 1; | ||
whlie(1) { | ||
if((lcm%num1 === 0) || (lcm%num2 === 0)) break; | ||
lcm++; | ||
} | ||
return lcm; | ||
} | ||
|
||
getLeastCommonMultiple(5, 10); | ||
``` | ||
|
||
## 풀이 | ||
<img src='./img/math_2.JPG' width="500px" alt="최소공배수" /> |