baekjoon - 베르트랑공준(4948)

ohbin Kwon·2022년 3월 27일
0

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

나의 풀이

const input = require('fs')
  .readFileSync(process.platform === 'linux' ? '/dev/stdin' : './ex.txt')
  .toString()
  .trim()
  .split('\n')
  .map( n =>  Number(n))
  input.pop()

  for(let num of input){
    countPrime = 0;
    for(let currentNum = num + 1; currentNum<=num*2; currentNum++){
      if(isPrime(currentNum)){
        countPrime += 1
      }
    }
    console.log(countPrime)
  }

  function isPrime(number){
    for(let a = 2; a<=Math.floor(Math.sqrt(number)); a++){
      if(number % a === 0){
        return false
      }
    }
    return true
  }

10896kb, 1336ms

다른 사람 풀이

profile
개발 로그

0개의 댓글