JavaScript implementation of the above idea to process queries of finding a number with maximum divisors .
let maxn = 10005 ; let INF = 999999 ; let smallest_prime = new Array ( maxn ) ; for ( let i = 0 ; i < maxn ; i ++ ) { smallest_prime [ i ] = 0 ; } let divisors = new Array ( maxn ) ; for ( let i = 0 ; i < maxn ; i ++ ) { divisors [ i ] = 0 ; } let segmentTree = new Array ( 4 * maxn ) ; for ( let i = 0 ; i < 4 * maxn ; i ++ ) { segmentTree [ i ] = 0 ; }