๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 1978๋ฒˆ : ์†Œ์ˆ˜ ์ฐพ๊ธฐ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 7. 24.

 

 

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();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€