fork(1) download
  1. /*
  2. Given an integer n, return the number of prime numbers that are strictly less than n.
  3.  
  4.  
  5.  
  6. Example 1:
  7.  
  8. Input: n = 10
  9. Output: 4
  10. Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
  11. Example 2:
  12.  
  13. Input: n = 0
  14. Output: 0
  15. Example 3:
  16.  
  17. Input: n = 1
  18. Output: 0
  19. */
  20.  
  21. let n = 10
  22. let output = 0
  23. let count = 0
  24.  
  25. for (let i=1; i<=n; i++){
  26. for(let j=1; j<=i; j++){
  27. if(i%j === 0) count = count+1
  28. }
  29. if(count === 1) output = output +1
  30. count = 0
  31. }
  32.  
  33. console.log(output)
  34.  
  35.  
  36.  
Success #stdin #stdout 0.03s 16792KB
stdin
Standard input is empty
stdout
1