Python 3 implementation of the above idea to process queries of finding a number with maximum divisors .
maxn = 1000005 NEW_LINE INF = 99999999 NEW_LINE smallest_prime = [ 0 ] * maxn NEW_LINE divisors = [ 0 ] * maxn NEW_LINE segmentTree = [ 0 ] * ( 4 * maxn ) NEW_LINE