Skip to content

Instantly share code, notes, and snippets.

@YeXiaoRain
Created March 27, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YeXiaoRain/b53a262f3a92f73281d9b0e042fc02a9 to your computer and use it in GitHub Desktop.
Save YeXiaoRain/b53a262f3a92f73281d9b0e042fc02a9 to your computer and use it in GitHub Desktop.
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;
};
@CroMarmot
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment