Python with sympy, 69 69 56 bytes
-13 bytes thanks to alephalpha (by upgrading to sympy 1.1 and using primeomega(n+2)
to replace sum(factorint(n+2).values())
)
...taking over from Gryphon's deleted submission.
from sympy import*
lambda n:sum(factorintprimeomega(n+2).values())<3*isprime(n)
An unnamed function returning True
for Chen primes and False
otherwise.
Counts the factors of n+2
by summing its prime factor's multiplicities.
Note that 3
is multiplied by isprime(n)
before the <
comparison is made, so for non-prime n
the code tests if n+2
has less than 0
factors (always yielding False
), while for prime n
it checks whether n+2
is prime or semi-prime.