Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

2 of 3
added 133 characters in body
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

CJam, (削除) 26 (削除ここまで) 27 bytes

ri){mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

EDIT: Forgot n was inclusive.

Try it online!

Explanation

ri e# Take an int as input
 ){mp}, e# Take the range up and including to the input, 
 e# including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length 
 e# is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

AltStyle によって変換されたページ (->オリジナル) /