20250917 baekjoon
This commit is contained in:
parent
93916853da
commit
4d65adb5e1
24
code_study/Baekjoon/ts/4948.ts
Normal file
24
code_study/Baekjoon/ts/4948.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export {};
|
||||||
|
|
||||||
|
const maxNum: number = 123456*2;
|
||||||
|
let isPrime: boolean[] = Array.from({length: maxNum + 1}, (_, i) => i>1 ? true : false);
|
||||||
|
|
||||||
|
for(let i=2; i*i <= maxNum; i++) {
|
||||||
|
if (isPrime[i]) {
|
||||||
|
let num: number = i*i;
|
||||||
|
while(num <= maxNum) {
|
||||||
|
isPrime[num] = false;
|
||||||
|
num += i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const input: number[] = require("fs").readFileSync(0).toString().trim().split('\n').map(Number);
|
||||||
|
for(let n of input) {
|
||||||
|
if (n===0) break;
|
||||||
|
let count: number = 0;
|
||||||
|
for(let i=n+1; i<=2*n; i++) {
|
||||||
|
if (isPrime[i]) count++;
|
||||||
|
}
|
||||||
|
console.log(count);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user