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
}
P=1;
for(i=0;i<c-1;i++){ //test sigma(x) for all i<c (see wikipedia)
P*=(Math.pow(p[i],e[i])-1)/(p[i]-1); //build the product
if(p[i+1]>P+1){
s=0 //fails sigma-test
break
}
}
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);