Find the largest banknote Banknotes in many countries come in denominations of 1,2,5,10,20,50,100,200,500,1000, etc. That is, one of \$ \{ 1,2,5\} \$ times a power of \$10\$. This is OEIS A051109, except we'll extend the sequence to bigger values.
Given a positive integer as the input, the program should output the largest bank note that is less than or equal to the input. The input will be less than \$2^{63}\$.
Examples:
1 =&gt; 1
2 =&gt; 2
3 =&gt; 2
5 =&gt; 5
9 =&gt; 5
42 =&gt; 20
49 =&gt; 20
50 =&gt; 50
99 =&gt; 50
100 =&gt; 100
729871 =&gt; 500000
3789345345234 =&gt; 2000000000000
999999999999999999 =&gt; 500000000000000000
Python 2, 39 bytes

f=lambda n:n&gt;9and 10*f(n/10)or 5&gt;&gt;5/-~n

Try it online!