Python3 implementation of the above approach
limit = 1000000000 NEW_LINE MAX_PRIME = 2000000 NEW_LINE MAX = 1000000 NEW_LINE I_MAX = 50000 NEW_LINE mp = { } NEW_LINE b = [ 0 ] * MAX NEW_LINE p = [ 0 ] * MAX NEW_LINE j = 0 NEW_LINE prime = [ True ] * ( MAX_PRIME + 1 ) NEW_LINE