const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
const input = fs
.readFileSync(path)
.toString()
.trim()
.split('\n')
.map((x) => Number(x));
function solve(input) {
let M = input.shift();
let N = input.shift();
let temp = new Array();
for (i = M; i <= N; i++) {
if (i === 1) {
continue;
} else {
let count = 1;
for (j = 2; j <= i - 1; j++) {
if (i % j === 0) {
count = 0;
break;
} else {
continue;
}
}
if (count) {
temp.push(i);
}
}
}
if (temp.length === 0) {
console.log(-1);
} else {
console.log(temp.reduce((acc, cur) => acc + cur));
console.log(temp[0]);
}
}
solve(input);
2581๋ฒ: ์์
M์ด์ N์ดํ์ ์์ฐ์ ์ค ์์์ธ ๊ฒ์ ๋ชจ๋ ์ฐพ์ ์ฒซ์งธ ์ค์ ๊ทธ ํฉ์, ๋์งธ ์ค์ ๊ทธ ์ค ์ต์๊ฐ์ ์ถ๋ ฅํ๋ค. ๋จ, M์ด์ N์ดํ์ ์์ฐ์ ์ค ์์๊ฐ ์์ ๊ฒฝ์ฐ๋ ์ฒซ์งธ ์ค์ -1์ ์ถ๋ ฅํ๋ค.
www.acmicpc.net
์ฃผ์ด์ง ๋ฒ์ ๋ด์์ ์์์ ํด๋นํ๋ ์ซ์๋ง ์๋ก์ด ๋ฐฐ์ด์ ์ถ๊ฐํด์ฃผ๊ณ
๊ทธ ๋ฐฐ์ด์ ํฉ๊ณผ ์ต์๊ฐ์ ๊ตฌํด์ฃผ๋ ์์ผ๋ก ํด๊ฒฐ
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 1929 (0) | 2022.05.22 |
---|---|
[JS] 11653 (0) | 2022.05.22 |
[JS] 1978 (0) | 2022.05.22 |
[JS] 10757 (0) | 2022.05.21 |
[JS] 2839 (0) | 2022.05.21 |