JavaScript (ES6), 78 bytes
f=p=>p>4?(P=n=>n%--x?P(n):x<2)(x=p)&P(x=p-~p)&P(x=--p/2)?[...f(p),p+1]:f(p):[]
Arnauld
- 205.5k
- 21
- 187
- 670
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchangef=p=>p>4?(P=n=>n%--x?P(n):x<2)(x=p)&P(x=p-~p)&P(x=--p/2)?[...f(p),p+1]:f(p):[]