[Question]
  [
A number is a Chen prime if it satisfies two conditions:
* It is prime itself
* Itself plus two is either a prime or a semi-prime.
A prime is a number where it has exactly two divisors and those divisors consist of itself and one.
A semi-prime is a number which is the product of two primes. (Note that 12 = 2\*2\*3 is not semi-prime, but 25 = 5\*5 is).
Your task is to determine if a number is a Chen prime. You should output any truthy value for yes and any falsy value for no.
The input will be any integer greater than or equal to one. It may also be taken as a string, character array, or an array or digits.
## Examples:
```
101 -> truthy
223 -> falsy
233 -> truthy
1 -> falsy
```
This is OEIS [A109611](https://oeis.org/A109611).
This is, in part, inspired by [Am I a Sophie Germain prime?](https://codegolf.stackexchange.com/questions/131604/am-i-a-sophie-germain-prime) which, unfortunately, got closed as a duplicate, so I'm posting a somewhat related challenge which isn't a duplicate.
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 7 bytes
```
ṗ+₂ḋl≤2
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@HO6dqPmpoe7ujOedS5BChgZGwMAA "Brachylog – Try It Online")
### Explanation
```
ṗ         Input is prime       
   ḋ      The prime factorization of…
 +₂       … Input + 2…
    l≤2   … has 2 or less elements
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
p¹ÌÒg3‹*
```
[Try it online!](https://tio.run/##MzBNTDJM/f@/4NDOwz2HJ6UbP2rYqfX/v5GxMQA "05AB1E – Try It Online")
### Explanation
```
p¹ÌÒg3‹*   Argument n
p          Push isPrime(n)
 ¹ÌÒ       Push list of prime factors of (n+2)
    g3‹    Length of list is lower than 3
       *   Multiplication of boolean values, 0 if either is 0 (false)
```
[Answer]
# Pyth, 10 bytes
```
&P_Q>3lP+2
```
[Try it online!](https://pyth.herokuapp.com/?code=%26P_Q%3E3lP%2B2&input=233&debug=0)
**How?**
```
&P_Q>3lP+2  # input: Q
        +2  # Q + 2
       P    # prime factors
    >3l     # length lower than 3?
 P_Q        # Q is prime?
&           # and both results
```
[Answer]
# [ArnoldC](https://lhartikk.github.io/ArnoldC/), 1339 bytes
```
LISTEN TO ME VERY CAREFULLY q
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE p
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE c
YOU SET US UP 0
HEY CHRISTMAS TREE d
YOU SET US UP 0
HEY CHRISTMAS TREE l
YOU SET US UP p
STICK AROUND l
GET TO THE CHOPPER d
HERE IS MY INVITATION p
I LET HIM GO l
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE d
BULLSHIT
GET TO THE CHOPPER c
HERE IS MY INVITATION c
GET UP 1
ENOUGH TALK
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER l
HERE IS MY INVITATION l
GET DOWN 1
ENOUGH TALK
CHILL
I'LL BE BACK c
HASTA LA VISTA, BABY
IT'S SHOWTIME
HEY CHRISTMAS TREE p
YOU SET US UP 0
GET YOUR ASS TO MARS p
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
HEY CHRISTMAS TREE n
YOU SET US UP 0
GET YOUR ASS TO MARS n
DO IT NOW q p
HEY CHRISTMAS TREE g
YOU SET US UP 42
GET TO THE CHOPPER g
HERE IS MY INVITATION n
YOU ARE NOT YOU YOU ARE ME 2
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE g
GET TO THE CHOPPER p
HERE IS MY INVITATION p
GET UP 2
ENOUGH TALK
GET YOUR ASS TO MARS n
DO IT NOW q p
GET TO THE CHOPPER g
HERE IS MY INVITATION 5
LET OFF SOME STEAM BENNET n
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE g
TALK TO THE HAND "t"
BULLSHIT
TALK TO THE HAND "f"
YOU HAVE NO RESPECT FOR LOGIC
BULLSHIT
TALK TO THE HAND "f"
YOU HAVE NO RESPECT FOR LOGIC
YOU HAVE BEEN TERMINATED
```
[Try it online!](https://tio.run/##pVRNj9pADL3nV1hcuPTQstsf4ASTsZiM0/EElGPFqlwQy1b9/9QTdouWDSpojxk/@73nj/z8vX/ePW2OR8@aKEASaAhWFHuoMNKi876Hl4IhEM2hly5C5SU50tNHKZIUMLzGGkkSq77yBIei5hVBhhK0JK29IcfCkZV20egaVEiRCDaFJYNSgk6ha@HrGOjpFtDuAnQoNHG1BIzSmcZdUVvIPJoqS5W2pWiFHUUCVmh64LDihIklWC6DN7jjBmqxXArS1Q4S@mVRUoWdGeNpDnKoc1XFHswmalZbWuvUcRqj3Fyh3Axg0/3tHVn25NCaGQQiaUtVgoVE8FJzNVZ/d6X@yf9c1uGCoXLsfcFT76EkKNFaZhpRE4JHWFmL8Ys9l33BaaqgTtaJGxobweHDnDLnsB2oOiwYRjXYXICTWVpbn9cYBhOoywwFhLILlQNZwI@ONIs/bdkZOjTETDf2rmuza8GmoTljIt@PKdvfpmx/VgYvpnOk0vai0uNsbArbK1M46bDrMoqBH96@7fRmd63Zdoz3cHWhX7frPcdNTbjD3vciX40sFqBihuy3go1tVQj2ur/TXYa98bo8/8mfyfmyPkZ/Tf5zLJ/J/RctKf8pKTYcbNnmx@Ps4eEv "ArnoldC – Try It Online")
(This is my first post on codegolf.SE, please let me know if this is formatted incorrectly. I realize this byte count is not competitive, this is just for fun.)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
+2ÆfL<3aÆP
```
[Try it online!](https://tio.run/##y0rNyan8/1/b6HBbmo@NceLhtoD/JoYGh9sPT0j7DwA "Jelly – Try It Online")
[Answer]
# [Python](https://docs.python.org/) with [sympy](http://www.sympy.org), ~~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:primeomega(n+2)<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.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 29 bytes
The `3*isprime(n)` trick is stolen from [Jonathan Allan 's answer](https://codegolf.stackexchange.com/a/131738/9288).
```
n->bigomega(n+2)<3*isprime(n)
```
[Try it online!](https://tio.run/##DYoxDoAgDAC/0jhRhQR0Ff6CCZAOFIL@v3a54e5mXuTalApR2KWH2uilZcPHife10zsX9WIYpY5lGCIEC8F7Cxr4U7OBS4qqD6L8 "Pari/GP – Try It Online")
[Answer]
# Java 8, ~~85~~ ~~84~~ 83 bytes
```
n->{int a=n+2,b=0,c=0,i=1;for(;i++<n;b+=n%i<1?1:0)c+=a%i<1?1:0;return n>1&b<2&c<3;}
```
-1 bytes thanks to *@OlivierGrégoire* by using an iterative approach instead of recursive.
**Explanation:**
[Try it here.](https://tio.run/##hY7BbsIwEETv@Yq9FDkyRHFyq2P6BeXCsephbUxlGtaR4yBVKN@eLi09Vkg7h9kZ6c0JL7iJg6fT4XNxPY4jvGKgawEQKPt0ROdhd7MANsbeI4ETHAGVmr8zi2/MmIODHRAYWGizvd4qaEg2a2vqtWMFo/QxJqGDlB1pKw09hU69qOe6dNLgn9HJ5ykR0FatbNesXNfqedEFY4bJ9oy50y4xHODMa8U@p0Afb@@A5e/U/deY/bmKU64GjnJPgionVK3Kn9n/NpqmfdRoHzXujLmYl28)
```
n->{            // Method with integer parameter and boolean return-type
  int a=n+2,    //  Start `a` at the input + 2
      b=0,c=0,  //  Start `b` and `c` at 0
      i=1;      //  Start `i` at 1
  for(;i++<n;   //  Loop from 1 to `n` (and raise `i` immediately by 1)
    b+=n%i<1?   //   If the input is divisible by `i`
        1       //    Raise `b` by 1
       :        //   Else:
        0)      //    Leave `b` as is
    c+=a%i<1?   //   If the input + 2 is divisible by `i`:
        1       //    Raise `c` by 1
       :        //   Else:
        0;      //    Leave `c` as is
                //  End of loop (implicit / single-line body)
  return n>1    //  Return if the input is larger than 1
         &b<2   //   And `b` is now smaller than 2
         &c<3;  //   And `c` is now smaller than 3
}               // End of method
```
[Answer]
# Mathematica, 28 bytes
```
PrimeQ@#&&PrimeOmega[#+2]<3&
```
[Answer]
# JavaScript (ES6), ~~63~~ 61 bytes
```
g=(e,i=e)=>i--<3?1:e%i?g(e,i):g(i)+1
f=e=>e>1&g(e)<2&g(e+2)<3
```
```
Test cases:<br><textarea id=i rows=6 oninput="go()">101&#10;223&#10;233&#10;1</textarea><br><pre id=q></pre><script>window.onload=function go(){document.getElementById('q').innerHTML=document.getElementById('i').value.split('\n').map(e=>e+' -> '+f(+e)).join('\n')}</script>
```
Defines a function `f` that takes `n` as argument and returns the result. Im very happy with how `g` turned out; it counts the number of prime factors in a number.
*2 bytes saves thanks to Kevin Cruijssen's `&` trick.*
### Ungolfed
```
Ω = (n,          // Ω(n) = number of n's prime factors, n > 1.
    i = n) =>    // Start iterating from i = n - 1. Since we'll immediately
                 // decrement i, n is used here.
    --i          // Immediately decrement i.
    < 2          // If i = 0 or i = 1, n is a prime at this point.
    ? 1 :        // Therefore Ω(n) = 1.
    n % i != 0 ? // If n is not divisible by i,
    Ω(n, i)      // try again with i := i - 1 (immediately decremented, so use i).
    : Ω(i) + 1   // n is divisible by i. Since we're counting down from n - 1
                 // and i is the first such number, i is n's largest non-trivial
                 // divisor, and thus n/i is a prime.
                 // Therefore Ω(n) = Ω(i) + Ω(n/i) = Ω(i) + 1.
is_chen = n =>     // An integer n ≥ 1 is a Chen prime if and only if:
    n > 1          // n > 1,
    & Ω(n) < 2     // Ω(n) = 1 < 2, i.e. n is a prime, and
    & Ω(n + 2) < 3 // Ω(n + 2) < 3, i.e. n + 2 is a prime or a semiprime.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~22~~ ~~20~~ ~~19~~ ~~13~~ 12 bytes
```
U°j ©2¨°Uk l
```
* 6 bytes saved thanks to obarakon's suggestion of a different method.
[Test it](http://ethproductions.github.io/japt/?v=1.4.5&code=VbBqIKkyqLBVayBs&input=MTAx)
[Answer]
# PHP, 64 bytes
```
for($i=$n=$argn+2;--$i;$argn%$i?:$q++)$n%$i?:++$p;echo$p<4^--$q;
```
prints `0` for truthy, other integers for falsy. Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/2b6da5ac5d3bb48251ac49b3fd5f59764af0237d).
**breakdown**
```
for($i=$n=$argn+2;--$i; # loop $i from N+1 to 1
    $argn%$i?:$q++)         # if $i divides N, increment $q
    $n%$i?:++$p;            # if $i divides N+2, increment $p
echo$p<4                # $p is 1 for a prime, 3 for a semiprime
    ^--$q;              # $q is 2 for prime; so this is 1^1 (==0) for a Chen Prime
```
**consistent falsy value, 65 bytes:**
```
for($i=$n=2+$k=$argn;--$i;$k%$i?:$q++)$n%$i?:++$p;echo$p<4&$q==2;
```
prints `1` for truthy and `0` for falsy.
[Answer]
# Regex (ECMAScript), 31 bytes
```
^(?!((xx+)(\2(xx))*)(\1\4)+$)xx
```
[Try it online!](https://tio.run/##Tc0xT8MwEAXgv9JGSL1riJtUFUOD04mhSwcYKUhWenUOXDuyTRNK@e0hDEhM7@l9w3tTZxVqz23MQssH8idn3@lz8NJSN3kk/dC3ABdZLebDK2ymAH2fIuyXYyLOx1bsV5jeYN8P88UFRXRP0bPVgCIYrgnubrMVYtk1bAjASE/qYNgSIE6l/TAGv7Q0IrSGI8yyGZZ8BLBSC0NWxwar5fXKYad2wLJVPtDWRtDP@QviH9B/sFWxKda/jLHxrku29qwMHyZeWU3rSZKa8ug8lHwvqeQ0xfEw6RPhqSUVgVGcVKwb8Ii1s8EZEsbpcS@/hyIr8jz/AQ) (showing all Chen primes ≤ 1000)
Given a string of **n** `x`s this regex will match if and only if **n** is a Chen prime.
It asserts that **n** is greater than 2 and that the string is not of the form `((xx+)(\2(xx))*)(\1\4)+`  
This regex has two meanings, depending on how many times `(\2(xx))` is repeated.  
When it is repeated 0 times, the regex can be simplified to `(xx+)\1+`, which matches composite numbers.  
When it is repeated a positive number of times, the regex is equivalent to `((xx+)(\2xx)+)(\1xx)+`
That regex requires some explanation, however, I will provide little insight.  
If you go through the algebra you find that `((xx+)(\2xx)+)(\1xx)+` matches numbers of the form `a*b*c-2` where `a≥4,b≥2,c≥2`.  
So it will match (almost) whenever **n**+2 has more than 2 prime factors. (i.e neither prime nor semi-prime)  
Note that it doesn't match 6, 10, 16 or 25, but that this doesn't matter, because they are all composite.
So `(?!((xx+)(\2(xx))*)(\1\4)+$)` will match as long as **n** is not composite, and **n**+2 is either prime or semi-prime.  
Unfortunately this includes 1 (and 0), so we then check that **n** is at least 2 with `xx`
A couple of different "31-byters" are:
```
^xx(?!((x*)(\2xx)+)\1?(\1xx)*$)
^(?!(xx((x*)(\3xx)+))\2?\1*$)xx
```
[Answer]
# [Python 3](https://docs.python.org/3/) with SymPy, ~~73~~ 71 bytes
```
lambda n:(sum(factorint(n+2).values())<3)&isprime(n)
from sympy import*
```
[Try it online!](https://tio.run/##RctBCsIwEIXhfU@RlcyoSJvZid7ETdQGA53JkKRCTh@rFbp6/B88reUVhZq/3trk@P50Rs6QZwbvHiWmIAXkYPH0dtM8ZkC8EO5C1hR4BMHOp8gmV9ZqAmtMZd/09xqOxsOA2P2zX6HfyFr60jIb0Uq0UPsA "Python 3 – Try It Online")
---
This is a more-golfed version of an answer posted here earlier, but it seems to have been deleted.
---
Thanks to @JonathanAllan for saving 2 bytes!
[Answer]
# [PHP](https://php.net/), 87 bytes
```
for($b=($a=$argn)+$i=2;2<$a+$b;)$a%$i?$b%$i?$i++:++$d*$b/=$i:++$c*$a/=$i;echo$c<2&$d<3;
```
[Try it online!](https://tio.run/##Hcg7DoAgEEXR3mWQp1GnMGDnMHEtA36gUeL@E4w2Nye3pFL9WlJpoM95ibHWcD3up0eQHir/HghZHDsPJQQeoC3yivA3Ey1E2EaESZA/xxH6mfeYbkTvOmx@5lpf "PHP – Try It Online")
# [PHP](https://php.net/), 87 bytes
```
for(;$n<2;)for($a=$argn+$n++*$i=2;1<$a;)$a%$i?$i++:++$r[$n]*$a/=$i;echo$r[1]<2&$r[2]<3;
```
[Try it online!](https://tio.run/##HYk9CoUwEAZ7jyGf8nQLSV7nbvAgkmIRNWliyP0h/lQzzOSQqyw55AZazuRaY1qux1V@jCSWh1eh7ruERDQiOstGoDxAO8QFkWgmQlmR/AidHCLvW7ieYrzY/qH18udabw "PHP – Try It Online")
[Answer]
# APL NARS, 23 chars
```
{1≥⍵:0⋄(1=⍴π⍵)∧3>⍴π⍵+2}
```
Here π⍵ return the array of factors of ⍵ different from 1; some test:
```
  f←{1≥⍵:0⋄(1=⍴π⍵)∧3>⍴π⍵+2}
  f 101
1 
  f 223
0 
  f 233
1 
  f 1
0
  f ¯10
0
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~49~~ 41 bytes
```
->n{/^(.?|((..+)\3+))(\2+|..)$/!~?l*n+=2}
```
[Try it online!](https://tio.run/##BcHRCkAwFADQX7GS7rV2d/E8PsSmePCEllKT8evXOee13LI6Mf3x2AloyABEGn2nEcG3OhNhadU3bPWhXftKLICJGmZG2uf45JTXMYWqSq8ZlYpBfg "Ruby – Try It Online")
Thanks H.PWiz for -8 bytes
### How?
First thing, get a string of `'l'` repeated n+2 times. Then apply a regex to check if:
* Length is 2 or 3 `(.?)(..)`
* Length is a composite number plus 2 `((..+)\1)(..)`
* Length is a product of at least 3 numbers `((..+)\2)\1+`
The 2 regex parts generate a fourth case which doesn't make sense and is safe to ignore: `(.?)\2+`, that resolves to empty string or a single character because `\2` is empty.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
&<3Lp+2¹ṗ
```
[Try it online!](https://tio.run/##yygtzv7/X83G2KdA2@jQzoc7p////98QAA "Husk – Try It Online")
## Explanation
```
&<3Lp+2¹ṗ
        ṗ input is prime?
&         and
   L      Length of
    p     prime factorization of
     +2¹  input + 2
 <3       less than 3?
```
[Answer]
# Julia, 59 bytes
```
x->((0∉x%(2:x-1))&(length(find(x->x==0,(x+2)%(2:x)))<=2))
```
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 11 bytes
3\*isprime(x) stolen from [Jonathan Allan's answer](https://codegolf.stackexchange.com/a/131738/9288)
```
←Đṗ3*⇹2+ḋŁ>
```
[Answer]
# [Haskell](https://www.haskell.org/), 163 bytes
```
p k=last$(not$elem 0(map(mod k)[2..k-1])):[1>2|k<=1]
r=round
s n=p(r n)||any(\(a,b)->p(r a)&&p(r b))[(n/x,x)|x<-[2..n],n/x==(fromIntegral.r)n/x]
c n=p(r n)&&s(n+2)
```
[Try it online!](https://tio.run/##Pcy9DoIwFEDhnae4AyH3RkDBzVB2nwEZyo9K2l6aUhNMePcKi9NJvuG85aJGrUOwoISWi4@RZx@PejRwQSMtmnkARU2Z5yorWqJbU9TlpipRtJETbv7wEC3AwqIDpm2T/MUHyrSjrD5MUpIc7Yga5POarrStVXYMuU13EAKfbjZ39uPLSZ072rGN@v8zSRbkU0nByIlBgHUTe4ihh/J6DT8 "Haskell – Try It Online")
]