JSFiddle - React, Tailwind, and code Playground
JavaScript
function y(r){
for(n=r-1,k=1;n;k++)
//I'm quite proud of this loop.
//n is the number of Practical numbers left to find, k is the number itself
if(
p=[], //prime factors of k
e=[], //exponents
c=0, //number of prime factors
P=s=1, //sigma-product and sigma (see wikipedia)
!((x=k)%2|1==x) //odd numbers apart from 1 automatically fail
){
while(x>1){ //factorise
for(f=x,j=2;j<=Math.sqrt(f);j++) //least divisor test
if(f%j==0){
f=j;
break //found a factor
}
f!=p[c-1]
?(p.push(f),e.push(2),c++) //if it's new, add it to the list
:e[c-1]++; //otherwise increment the exponent
x/=f //divide the factor out
}
for(i=0;c>i;i++){ //sigma-testing! loop through the primes once
if(p[i]>P+1){ //sigma-test the previous loop (saves 2 chars to put it before not after)
s=0;
break //as soon as the test fails, exit
}
P*=(Math.pow(p[i],e[i])-1)/(p[i]-1) //increment the test
}
s&&n-- //only decrement n if the sigma-test is passed
}
return k-1 //we end up one larger than k because the for loop has k++
}
document.body.innerHTML+=y(1000);