Skip to content
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

Open
Sunny-117 opened this issue Nov 3, 2022 · 3 comments
Open

素数 #96

Sunny-117 opened this issue Nov 3, 2022 · 3 comments

Comments

@Sunny-117
Copy link
Owner

No description provided.

@bearki99
Copy link

function judgeIs(num) {
  let cnt = 0;
  for (let i = 1; i <= num; i++) {
    if (num % i === 0) cnt++;
  }
  return cnt === 2;
}

@veneno-o
Copy link
Contributor

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;
}

@kangkang123269
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants