Only thing i can think is that I am calculating primes w.r.t to the upper bound. so, its a waste of space as well as time. for example if my input is something like 999900100 1000000000, which is well within the range, it will time out, since it will first calculate all the prime numbers from 2 till 1000000000 and then run a loop to check which one belongs under the range. how to solve this and shorten the prime range so that i don’t have to calculate from 2 till the end?