##Jelly, 5 bytes
Alternate approach to @Dennis' existing 5-byte Jelly answer:
B;ÆPP
How it works:
ÆP Returns 1 if the input is a prime, 0 otherwise
B Returns the binary representation of the input as a list [1, 0, 1, 1, ...]
; And attach to this list
ÆP a 1 if the input is a prime, 0 otherwise
P Calculates the product of this list of 1's and 0's
Since a Mersenne Prime is one less than a power of 2, its binary representation is excusively 1's. The output therefor is 1 for Mersenne primes, and 0 in all other cases .
steenbergh
- 8.2k
- 1
- 27
- 43