Algorithm
- ์์ ์ฐพ๊ธฐ -
๋ฌธ์
์ฃผ์ด์ง ์ N๊ฐ ์ค์์ ์์๊ฐ ๋ช ๊ฐ์ธ์ง ์ฐพ์์ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on("line", function (line) {
input.push(
line
.toString()
.split(" ")
.map((el) => +el)
);
}).on("close", function () {
input.shift();
input = input[0];
let count = 0;
for (let i = 0; i < input.length; i++) {
let torf = true;
if (input[i] <= 2) {
if (input[i] === 2) {
count++;
}
continue;
}
if (input[i] % 2 === 0) continue;
for (let j = 3; j < input[i]; j++) {
if (input[i] % j === 0) {
torf = false;
break;
}
}
if (torf) {
count++;
}
}
console.log(count);
process.exit();
});
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 2108๋ฒ : ํต๊ณํ (0) | 2021.07.26 |
---|---|
[๋ฐฑ์ค][Node.js] 2010๋ฒ : ํ๋ฌ๊ทธ (0) | 2021.07.25 |
[๋ฐฑ์ค][Node.js] 1977๋ฒ : ์์ ์ ๊ณฑ์ (0) | 2021.07.23 |
[๋ฐฑ์ค][Node.js] 1966๋ฒ : ํ๋ฆฐํฐ ํ (0) | 2021.07.21 |
[๋ฐฑ์ค][Node.js] 1934๋ฒ : ์ต์๊ณต๋ฐฐ์ (0) | 2021.07.19 |
๋๊ธ