Maximum number of unique prime factors | Javascript program to find maximum number of prime factors for a number in range [ 1 , N ] ; Return smallest number having maximum prime factors . ; Sieve of eratosthenes method to count number of unique prime factors . ; Return maximum element in arr [ ] ; driver program
function getMax ( Arr ) { let max = Arr [ 0 ] ; for ( let i = 1 ; i < Arr . length ; i ++ ) if ( Arr [ i ] > max ) max = Arr [ i ] ; return max ; } function maxPrimefactorNum ( N ) { 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 ; } return getMax ( arr ) ; } let N = 40 ; document . write ( maxPrimefactorNum ( N ) ) ;