Sieve of eratosthenes method to count number of unique prime factors .
let arr = new Array ( N + 1 ) . fill ( 0 ) ; for ( let i = 2 ; i * i <= N ; i ++ ) { if ( arr [ i ] == 0 ) for ( let j = 2 * i ; j <= N ; j += i ) arr [ j ] ++ ; arr [ i ] = 1 ; }