티스토리 뷰
https://www.acmicpc.net/problem/2609
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split(" ");
const nums = input.map(v => +v);
const gcd = Euclidean(nums[0], nums[1])
console.log(gcd)
const lcm = LCM(gcd, nums[0], nums[1])
console.log(lcm)
function Euclidean(a, b) {
let x;
let y;
if (a > b) {
x = a; y = b;
} else {
x = b; y = a;
}
let r;
while (y != 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
function LCM(gcd, a, b) {
return (a * b / gcd);
}
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 3036번 : 링 (0) | 2021.09.12 |
---|---|
Node.js) 백준 1934번 : 최소공배수 (0) | 2021.09.12 |
Node.js) 백준 2447번 : 별 찍기 - 10 (0) | 2021.09.12 |
Node.js)백준 1037번 : 약수 (0) | 2021.09.12 |
Node.js) 백준 5086번 : 배수와 약수 (0) | 2021.09.12 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 동적프로그래밍
- create databases;
- 다이나밍프로그래밍
- 면접비
- node.js
- 로드나인
- 서버개발
- 서버점검
- 롱베케이션
- 그래프
- 다이나믹프로그래밍
- 최소공통조상
- 면접질문
- DB 생성
- 투포인터
- MySQL
- 개발자면접
- 은둔청년체험
- create db
- 투포인터 연습
- MOD
- BFS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함