fork download
  1. const [len, input] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n')
  2.  
  3. const nums = input.split(/\s/).map(s => Number(s))
  4. let m = nums[0]
  5.  
  6. for (let i = 0; i < len - 1; i++) {
  7. m = Math.max(nums[i], nums[i + 1])
  8. }
  9.  
  10. if (m < 2) {
  11. console.log(0)
  12. } else {
  13. const arr = [false, false, ...new Array(m - 1).fill(true)] // index 0, 1 제외
  14. for (let i = 2; i <= Math.sqrt(m); i++) {
  15. if (arr[i]) {
  16. for (let j = i * i; j <= m; j = i + j) {
  17. arr[j] = false
  18. }
  19. }
  20. }
  21. console.log(nums.filter(x => arr[x]).length)
  22. }
Success #stdin #stdout 0.09s 31564KB
stdin
3
7 2 3
stdout
2