A C ++ implementation of the above idea to process queries of finding a number with maximum divisors .
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define maxn  1000005 NEW_LINE #define INF  99999999 NEW_LINE int smallest_prime [ maxn ] ; int divisors [ maxn ] ; int segmentTree [ 4 * maxn ] ;