for(auto i : primes){ //check for each prime less than 1e6 int st = 0; if(L % i == 0) st = L ; else st = (L / i + 1) * i; for(int j = st; j <= R; j += i){ //compression and mark that i is factor of j fact[j - L + 1].push_back(i); } }