2 Fix for x=1
source | link

Python 2Python 2 (Cython), 96 bytes

l=lambda p:min(filter(lambda p:all(p%n for n in range(2,p)),range(2,p*2p*3)),key=lambda x:abs(x-p))

Try it online!Try it online!

Python 2, 96 bytes

l=lambda p:min(filter(lambda p:all(p%n for n in range(2,p)),range(2,p*2)),key=lambda x:abs(x-p))

Try it online!

Python 2 (Cython), 96 bytes

l=lambda p:min(filter(lambda p:all(p%n for n in range(2,p)),range(2,p*3)),key=lambda x:abs(x-p))

Try it online!

1
source | link

Python 2, 96 bytes

l=lambda p:min(filter(lambda p:all(p%n for n in range(2,p)),range(2,p*2)),key=lambda x:abs(x-p))

Try it online!