Last active
October 3, 2023 02:26
-
-
Save zlrlo/1155f23cbddd10ff4d834443a730f0e4 to your computer and use it in GitHub Desktop.
[JS] 소수 구하는 가장 빠른 방법
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getPrime(n) { | |
| let answer = 0; | |
| let prime = [false, false, ...Array(n - 1).fill(true)]; | |
| for(let i = 2; i * i <= n; i++) { | |
| if(prime[i]) { | |
| for(let j = i * 2; j <= n; j += i) { | |
| prime[j] = false; | |
| } | |
| } | |
| } | |
| answer = prime.filter(Boolean).length; | |
| return answer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment