JSFiddle - React, Tailwind, and code Playground
JavaScript
function practical(N){ //find the Nth practical number
for(n=N-1,k=1;n;k++){ //k is the number
p=[]; //prime factors
e=[]; //exponents
c=0; //number of prime factors
s=1; //sigma of this number
if((x=k)%2|x==1)
continue; //odd numbers greater than 1 can never be practical
while(x>1){ //factorise
f=x; //smallest factor
for(j=2;j<=Math.sqrt(f);j++) //find f
if(f%j==0){
f=j;
break
}
if(f!=p[c-1]){ //new prime factor
p.push(f);
e.push(2);
c++
}else e[c-1]++; //increase exponent of existing PF
x/=f
}
for(i=1;i<c;i++){ //test sigma(x) for all i<c (see wikipedia)
j=i;
P=1;
while(j--)
P*=(Math.pow(p[j],e[j])-1)/(p[j]-1); //build the product
if(p[i]>P+1)
s=0 //fails sigma-test
}
if(s)n-- //progress the for loop only if the sigma-test passes
}
return k-1; //we end up with k too high because we increment k after each iteration
}
document.body.innerHTML+=practical(1000);