Efficient method to check whether the nearest prime has distance $d$ or more?

94 Views Asked by At

Suppose, a prime $\ p\ $ is given.

How can I check efficiently whether the distance to the nearest prime is $\ d\ $ or more , if $\ d\ $ is given ?

My approach is to start with $\ c=2\ $ and as long as $\ p-c\ $ and $\ p+c\ $ are both not prime increasing $\ c\ $ , the distance of the nearest prime is then $\ c\ $

Can I , apart from some trial divisions , accelerate the procedure somehow ?