From 4d65adb5e1100b7cac644a37a14028ab4797b414 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Wed, 17 Sep 2025 21:43:52 +0900 Subject: [PATCH] 20250917 baekjoon --- code_study/Baekjoon/ts/4948.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 code_study/Baekjoon/ts/4948.ts diff --git a/code_study/Baekjoon/ts/4948.ts b/code_study/Baekjoon/ts/4948.ts new file mode 100644 index 0000000..ee86e55 --- /dev/null +++ b/code_study/Baekjoon/ts/4948.ts @@ -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); +} \ No newline at end of file