Ponchimeow / Practice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lisa 的圍巾 ( 50分 )

Ponchimeow opened this issue · comments

Lidemy, OJ Lisa的圍巾

目前50分,待檢修

function pa(s) {
  const arr = s.split(' ');
  const a = parseInt(arr[0]);
  const b = parseInt(arr[1]);
  let res = 0;
  if (a >= 1 && b <= 7000) {
    for (let i = a; i <= b; i += 1) {
      if (!isPrime(i)) {
        res += i;
      }
    }
    return res;
  }
}

function isPrime(n) {
  if (n === 1) return false;
  if (n === 2) return true;
  for (let i = 2; i < n; i += 1) {
    if (n % i === 0) return false;
    else return true;
  }
}