-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
素数 #96
Comments
|
function judeg(num){
if(num === 2 || num === 3) return true;
for(let i = 2; i <= Math.pow(num, 0.5); ++i){
if(num % i === 0) return false;
}
return true;
} |
function isPrime(num) {
if (num <= 1) return false; // 素数定义为大于1的自然数中,除了1和它本身以外不再有其他因数的自然数
if (num === 2) return true; // 2是唯一的偶素数
if (num % 2 === 0) return false; // 排除其他偶数
const sqrt = Math.sqrt(num);
for(let i = 3; i <= sqrt; i += 2) {
if (num % i === 0)
return false;
}
return true;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: