Skip to main content
4 of 5
added 10 characters in body
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off \$n\$ until \$n\$ is \$9\$ or less. Then returns one of \$\{1,2,5\}\$, whichever lays just below or equal to \$n\$.

Noodle9
  • 20.3k
  • 3
  • 21
  • 46