Haskell, 6153 bytes
f b=[x|x<-[b..],g<-[all$(<2).gcd x],g[bk<-1..b+1]>g[2[2..x-1]]1],mod x k+gcd(b^3-b)x<2]!!0
Searches for the smallest x
, upward starting from b
, satisfying this condition:
Define
g(s)
to check ifx
is coprime to all numbers ins
.Then demand:
g([b-1,b,b+1])
and notg([2,3..x-1])
.(So
x
passes all the "divisibility rules", but it's not prime.)
It's okay to start the search from b
instead of b+1
, because the answer will never be x=b
. (The guarantee that b>=2
means gcd(x,b) = gcd(b,b) = b > 1
.)Try it online!