Skip to content

Instantly share code, notes, and snippets.

@martian17
Created June 8, 2021 12:11
Show Gist options
  • Save martian17/c0af0cadf3809d2e9418f74d73980ed5 to your computer and use it in GitHub Desktop.
Save martian17/c0af0cadf3809d2e9418f74d73980ed5 to your computer and use it in GitHub Desktop.
このツイートに基づいて書いてみました。https://twitter.com/2_wykipedia/status/1402160697497165826
var primes = [];
var cond = [1];
for(var i = 2; i < 335; i++){
var flag = true;
var primeFlag = true;
for(var j = 0; j < primes.length; j++){
var prime = primes[j];
if(prime*prime > i)break;
primeFlag = primeFlag && (i%prime !== 0)
// flag === true if not divisible by any prime
flag = flag && (i%(prime*prime) !== 0);
}
if(primeFlag)primes.push(i);
//factors
var factors = [];
for(var j = 1; j <= Math.sqrt(i); j++){
if(i%j === 0){
//console.log(j);
factors.push(j);
factors.push(i/j);
}
}
//console.log(i,factors,factors.reduce((a,b)=>a+b),2*i);
if(flag && factors.reduce((a,b)=>a+b) < 2*i)cond.push(i);
}
console.log(primes);
console.log(cond);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment