Function to compute least prime divisor of i upto MAX element of the input array it will be space efficient if more test cases are there it 's  better to find prime divisor  upto upperbound of input element  it will be cost efficient
function preCompute ( ) { lpd = new Array ( MAX + 1 ) ; for ( let i = 0 ; i < lpd . length ; i ++ ) { lpd [ i ] = 0 ; } lpd [ 0 ] = lpd [ 1 ] = 1 ; for ( let i = 2 ; i * i <= MAX ; i ++ ) { for ( let j = i * 2 ; j <= MAX ; j += i ) { if ( lpd [ j ] == 0 ) { lpd [ j ] = i ; } } } for ( let i = 2 ; i <= MAX ; i ++ ) { if ( lpd [ i ] == 0 ) { lpd [ i ] = i ; } } }