Suppose, positive integers $N,a,b$ are given.
The object is to determine the smallest prime $p$ larger than $a$ such that $N$ modulo $p$ is smaller than $b$.
Can I determine $p$ efficiently (without just checking all primes until the desired prime is found) ?
Example
$$N=40!$$
$$a=9\cdot 10^{15}$$
$$b=10^{10}$$
Brute force gives the result :
? n=40!;a=9*10^15;a=nextprime(a+1);while(n%a>=10^10,a=nextprime(a+1));p=a;print(
p)
9000000017042521
?
Is there a way to speed up the search considerably ?