Algorithm
- ์์ ๊ตฌํ๊ธฐ -
๋ฌธ์
์ฒซ์งธ ์ค์ ์์ฐ์ M๊ณผ N์ด ๋น ์นธ์ ์ฌ์ด์ ๋๊ณ ์ฃผ์ด์ง๋ค. (1 ≤ M ≤ N ≤ 1,000,000) M์ด์ N์ดํ์ ์์๊ฐ ํ๋ ์ด์ ์๋ ์ ๋ ฅ๋ง ์ฃผ์ด์ง๋ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input;
rl.on("line", function (line) {
input = line
.toString()
.split(" ")
.map((el) => +el);
}).on("close", function () {
let decimal = [];
for (let i = input[0]; i <= input[1]; i++) {
let torf = true;
if (i <= 2) {
if (i === 2) decimal.push(i);
continue;
}
if (i % 2 === 0) continue;
for (let j = 3; j <= Math.sqrt(i); j += 2) {
if (i % j === 0) {
torf = false;
break;
}
}
if (torf) {
decimal.push(i);
}
}
console.log(decimal.join("\n"));
process.exit();
});
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 1966๋ฒ : ํ๋ฆฐํฐ ํ (0) | 2021.07.21 |
---|---|
[๋ฐฑ์ค][Node.js] 1934๋ฒ : ์ต์๊ณต๋ฐฐ์ (0) | 2021.07.19 |
[๋ฐฑ์ค][Node.js] 1924๋ฒ : 2007๋ (0) | 2021.07.17 |
[๋ฐฑ์ค][Node.js] 1919๋ฒ : ์ ๋๊ทธ๋จ ๋ง๋ค๊ธฐ (0) | 2021.07.16 |
[๋ฐฑ์ค][Node.js] 1764๋ฒ : ๋ฃ๋ณด์ก (0) | 2021.07.15 |
๋๊ธ