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

[๋ฐฑ์ค€][Node.js] 1929๋ฒˆ : ์†Œ์ˆ˜ ๊ตฌํ•˜๊ธฐ

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

 

 

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

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€