finding sum of prime numbers under 250

后端 未结 8 825
忘了有多久
忘了有多久 2020-12-19 18:52
var sum = 0

for (i = 0; i < 250; i++) {

    function checkIfPrime() {

        for (factor = 2; factor < i; factor++) {
            if (i % factor = 0) {
            


        
8条回答
  •  醉梦人生
    2020-12-19 19:42

    As per the "Sieve of Eratosthenes", I have implemented the code using JS:

    function isPrime(n){
      return ((n/2 === 1 || n/3 === 1 || n/5 === 1 || n/7 === 1)?true:(n%2===0 || n%3 === 0 || n%5 ===0 || n%7 === 0)?false:true);
    };
    
    var val = 250;
    
    let outArr = [];
    for(let i=2;i

提交回复
热议问题