백준 4948 nodejs

윤익·2022년 11월 5일
0

https://www.acmicpc.net/problem/4948

const fs = require('fs')
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n')
const [V, P] = [new Array(246913).fill(0), []]
for (let i = 2; i <= 246912; i++) {
  if (V[i]) continue
  P.push(i)
  for (let j = 1; i * j <= 246912; j++) V[i * j] = 1
} // 에라토스테네스의 체로 소수 배열 P 초기화
const A = []
input.pop()
for (const N of input)
  A.push(P.reduce((p, c) => p + +(c > +N && c <= 2 * +N), 0))
console.log(A.join('\n'))
profile
https://nickyoon.tistory.com/ 기술 블로그 이전

0개의 댓글