Created
March 27, 2019 13:38
-
-
Save YeXiaoRain/b53a262f3a92f73281d9b0e042fc02a9 to your computer and use it in GitHub Desktop.
This file contains 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
is_ONE = (v)=>{ | |
let ret = 0; | |
for(let i=1;i<=v;i++){ | |
// find divisor i | |
if(!(v%i)){ | |
let mu = 1; | |
// find prime factor of i | |
for(let j=2;j <= i;j++){ | |
if(i%j)continue; | |
// check if j is prime | |
let isprime = true; | |
for(let k=2;k*k<=j;k++){ | |
if(j%k == 0){ | |
isprime = false; | |
break; | |
} | |
} | |
if(isprime){ | |
if(!(i%(j*j))){ | |
mu = 0; | |
break; | |
} | |
mu*=-1; | |
} | |
} | |
ret += mu; | |
} | |
} | |
return ret; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.npmjs.com/package/@cromarmot/is-number-one now avaliable in npm