Python 2, 42 bytes
f=lambda n,p=2:n%p and f(n,p+1)or p**n%n<1
Since Python doesn't have any built-ins for primes, we make do with checking divisibility.
We find the smallest prime p
that's a factor of n
by counting up p=2,3,4,...
until n
is divisible by p
, that is n%p
is zero. There, we check that this p
is the only prime factor by checking that a high power of p
is divisible by n
. For this, p**n
suffices.
As a program:
43 bytes
n=input()
p=2
while n%p:p+=1
print p**n%n<1
This could be shorter with exit codes if those are allowed.
46 bytes
lambda n:all(n%p for p in range(2,n)if p**n%n)