[Question]
  [
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](https://oeis.org/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 => 1
2 => 2
3 => 2
5 => 5
9 => 5
42 => 20
49 => 20
50 => 50
99 => 50
100 => 100
729871 => 500000
3789345345234 => 2000000000000
999999999999999999 => 500000000000000000
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 39 bytes
```
f=lambda n:n>9and 10*f(n/10)or 5>>5/-~n
```
[Try it online!](https://tio.run/##NYyxCoMwGAZ3n@IbTRoxfyFQA@ZFSocUGxXaTwkuXXz1NEu3u@Fu/x7LxmspaXzHz3OKoGcYIieI1allL1ZtGS4E13cnS6pCrESOnF@tGLGicMHd6RpouXVi8OeHb7DnlQdoUGeq/AA "Python 2 – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, ~~24~~ ~~20~~ 19 bytes
*Credit to @DomHastings for shortening this entry.*
```
s/\B./0/g;y;3-9;225
```
[Try it online!](https://tio.run/##K0gtyjH9/79YP8ZJT99AP9260tpY19LayAgoaGZu8S@/oCQzP6/4v26BGwA "Perl 5 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 38 bytes
```
lambda a,*b:`5>>5/-~int(a)`+"0"*len(b)
```
[Try it online!](https://tio.run/##ZY3NbsMgEITv@xQrn2zXTfEPcoiEn6SH4BorSBgjoFJyyau7@Kdqq46QvmWGHewj3GZTLSN/X7SY@kGgKPL@cqVdR99en8qEVGTXl4QkuZYm7bNFTXZ2Af3DA4yzQ62MRGVW4@TDoMwF0BQo71Z@BDkgx0nY1AcXU6dssS2cvNUqpAnvkiwDdNJ/6hCfjmlu4t26@PHhcv5dVRzOUiLvsIRqRQX1DrqCAtvR7CGBhh0DJVtCgLFjKMlmRUBbsXNb7v4qqNszqxsaT1U3e8MvxY5/@ln@oy8 "Python 2 – Try It Online")
A function that takes in the number as characters, and returns a numeric string.
Use [xnor's formula](https://codegolf.stackexchange.com/a/210684/92237) to get from a digit to 1, 2, or 5.
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 30 bytes
```
{first /^(1|2|5)0*$/,($_...1)}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/Oi2zqLhEQT9Ow7DGqMZU00BLRV9HQyVeT0/PULP2f2FpZmpJTqVCcWKlgh5QQ1p@kUJOZl5q8X9DLiMuYy5TLksuEyMuE0suUwMuS0suQwMDAA "Perl 6 – Try It Online")
Counts down from the input, finding the first number that is a 1,2 or a 5 followed by only zeroes
[Answer]
# [J](http://jsoftware.com/), 26 bytes
```
(>:{:@#])1 2 5*<.&.(10&^.)
```
[Try it online!](https://tio.run/##ZYvNCoMwEITvPsVgQZNil/wSE9oiCD315F2PCr5CHz7d7bXLfPAx7Jy1pX7Ho6DHAIPC3Ajz8n5V9SyfMl1WbeEQr3fqSFnTbaSrrods1LDr5oBlHOOZyGQmSBHEopFKzBrR5PKYZOLTmH2IHOfD7@fvvg "J – Try It Online")
### How it works
```
(>:{:@#])1 2 5*<.&.(10&^.)                             250
                   (10&^.) logarithm to base 10          3.x
               <.&.        and floor                     3
                   (10&^.) and reverse the logarithm:  100
         1 2 5*            1 2 5 times that:   100 200 500
(>:     )                  input greater-equal list? 1 1 0
      #]                   take from list:         100 200
   {:@                     last element                200
```
[Answer]
# [R](https://www.r-project.org/), ~~51~~ 47 bytes
Golfed down 4 bytes by Giuseppe.
```
function(x,z=c(5,2,1)*10^nchar(x)/10)z[z<=x][1]
```
[Try it online!](https://tio.run/##Zc7hCoMgEAfw73uKg33REczTpIT5JNGggjYZKIhB9PKtqWPF/gjyO@8O/dp39gV6HSc7BOMsmYtFD0QWvEB6QXa3w7PzZKZXZHRplpue2wbbOEaQgtaApwgewRPEHjJCJqg9yjzEMtWBkqXeTKUORJaetzsVKq7qCnPPJ/krVa1EKbfDRZn37/Ld/RcK5@Ac9OYBo/PQWTA2wG/7Iesb "R – Try It Online")
[Answer]
# [Rockstar](https://codewithrockstar.com/online), 187 bytes
```
Listen to B
cast B at 0 into C
D is 5
E is 2
F is 1
let G be F
if C is as strong as E
let G be E
if C is as strong as D
let G be D
while B is as strong as 10
let B be B over 10
let G be G of 10
say G
```
Ungolfed and a bit more Rockstarish (yes this is valid syntax)
```
sunset was spellbound
god was a roundabout
Listen to the devil
cast the devil at sunset into the storm
(The kids are young don't let em grow up too fast)
Tommy is 5
Jimmy is 2
Alice is 1
(My kids are my heroes)
let my Hero be Alice
if the storm is as strong as Jimmy
let my Hero be Jimmy
if the storm is as strong as Tommy
let my Hero be Tommy
while the devil is as strong as god
let the devil be the devil over god
let my hero be my hero of god
say my hero
```
First time ever using this language, just having a bit of fun
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
⭆Ｓ∧¬κ÷⁵⊕÷⁵⊕ι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCO4BEil@yYWaHjmFZSWQLgamjoKjnkpGn75JRrZQLZnXolLZllmSqqGKYiTXJSam5pXkpqigVMiUxMCrP//Nza3sDQ2MQUiI2OT/7plOQA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
 Ｓ             Convert input to a string
⭆              Map over digits and join
    κ           Current index
   ¬            Is zero
  ∧             Boolean AND
           ι    Current digit
          ⊕     Incremented
         ⁵      Literal 5
        ÷       Integer divide
       ⊕        Incremented
      ⁵         Literal 5
     ÷          Integer divide
                Implicitly print
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~6~~ 5 bytes
```
Ω£İ₅←
```
[Try it online!](https://tio.run/##yygtzv7//9zKQ4uPbHjU1PqobcL///9NLM3NAA "Husk – Try It Online")
## Explanation
It's basically a built-in.
```
Ω£İ₅←   Implicit input.
    ←   Decrement
Ω       until
 £      is an element of
  İ₅    Infinite list of powers of 10 and multiples by 2 or 5:
            [1,2,5,10,20,50,100,200,500,..]
```
Here's a more interesting 10-byte solution that avoids `İ₅`:
```
Ωö€Ḋ10d↔d←
```
[Try it online!](https://tio.run/##yygtzv7//9zKw9seNa15uKPL0CDlUdsUIJ7w//9/E0tzMwA) Explained:
```
Ωö€Ḋ10d↔d←   Implicit input.
         ←   Decrement
Ω            until
 ö           composition of 4 functions:
        d     number to digits,
       ↔      reverse,
      d       back to number,
  €           is an element of
   Ḋ          list of divisors of
    10        10 (so 1, 2, 5 or 10, and the last one is impossible).
```
[Answer]
# [JavaScript](https://v8.dev/), 34 bytes
```
f=n=>n<2?1:n<5?2:n<10?5:10*f(n/10)
```
[Try it online!](https://tio.run/##bY7dCsIwDEbvfZJmoCb9oe3Y7LOMYUUZrTjZ69fdjs8QcnE4HPKatmmdP8/397yF1vJYxlsZdJK@DC7p/Qon1wt3WZWrMLW5lrUu98tSHyorITodiQZigDggEYjFkEXLMabQEkbN6xg8vm98iMa6fbWxf9owRO0H "JavaScript (V8) – Try It Online")
A recursive function that checks each denomination, otherwise divides by 10 and tries again.
Note that the last test case fails because it exceeds the maximum safe integer.
-6 bytes don't need to check `<1`
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 17 [bytes](https://github.com/abrudz/SBCS)
```
10⊥≢↑'125'(⍎⍸⊃⊣)⊃
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qW9CjtgmGRhbmXEBOQACQY2zy39DgUdfSR52LHrVNVDc0MlXXeNTb96h3x6Ou5kddizWB1P80oEKQYFfzofXGQGVAzcFBzkAyxMMz@H/aoRUKj3qnAklDBSMFYwVTBUsFQ0sFEyMFE0sFUwMFSyDXwEBB49B6Q21DAy1DC00FDQgNAA "APL (Dyalog Unicode) – Try It Online")
A tacit function that takes input as a string, and returns an integer. `⎕FR←1287` is needed to get exact results for high numbers.
### How it works
```
10⊥≢↑'125'(⍎⍸⊃⊣)⊃  ⍝ Input: a string of digits without leading zeros
                ⊃  ⍝ First char
     '125'( ⍸  )   ⍝ Interval index into '125'; 1→1; 2-4→2; 5-9→3
             ⊃⊣    ⍝ The char at the above index of '125'
           ⍎       ⍝ Eval it, so it becomes numeric
   ≢↑              ⍝ Pad with zeros to the length of the input
10⊥                ⍝ Convert from base 10 digits to integer
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~12~~ 10 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
I/O as an integer.
```
@AvXìw}aaU
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=QEF2WOx3fWFhVQ&input=NzI5ODcx)
---
## Alternative (w/ [`-m` flag](https://codegolf.meta.stackexchange.com/a/14339/)), 10 bytes
I/O as a string or an array of digits. Credit, again, to xnor for the formula to find the first digit.
```
V?T:5Á5/°U
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LW0&code=Vj9UOjXBNS%2bwVQ&input=IjcyOTg3MSI)
---
## Original (with `-h` flag), 12 bytes
I/O as integer strings.
```
#}ì úTUl)f§U
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWg&code=I33sIPpUVWwpZqdV&input=IjcyOTg3MSI)
```
#}ì úTUl)f§U     :Implicit input of integer string U
#}               :125
  ì              :To digit array
    ú            :Right pad each
     T           :  With 0
      Ul         :  To the length of U
        )        :End padding
         f       :Filter
          §U     :  Less than or equal to U
                 :Implicit output of last element
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~26 bytes~~ 21 bytes
```
efgQTm*d^Ttl+Qk[1 2 5
```
[Try it online!](https://tio.run/##K6gsyfj/PzUtPTAkVyslLqQkRzswO9pQwUjB9P9/E0tLAA "Pyth – Try It Online")
 
*Old Solution:*
```
V60 aY*h^%N3 2^T/N3;efgQTY
```
Explanation:  
Using `((n % 3) ** 2 + 1) * 10**int(n/3)` To calculate a the banknote for n in the series.
```
V60 aY*h^%N3 2^T/N3;efgQTY
V60                         Looping 60 times.
      *h^%N3 2^T/N3         Calculate the current iterations banknote value
    aY                      Append it to list Y
                     fgQTY  Filter the list for all values less than or equal to input
                    e       Grab the last value in the list.
```
[Try it online!](https://tio.run/##K6gsyfj/P8zMQCExUisjTtXPWMEoLkTfz9g6NS09MCTy/38TS0sA "Pyth – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 14 bytes
```
:ḟ≤←¹s521mK'0t
```
[Try it online!](https://tio.run/##yygtzv7/3@rhjvmPOpc8aptwaGexqZFhrre6Qcn///@VTA2VAA "Husk – Try It Online")
This is my first Husk answer.
In Haskell this would look like
```
\x -> (find (<= head x) (show 521)) : (map (const '0') (tail x))
```
[Answer]
# [JavaScript (V8)](https://v8.dev/), 62 bytes
```
n=>(e=Math.log10(n)|0,x=n/(y=10**e),y*((x>=5)*5||(x>=2)*2||1))
```
[Try it online!](https://tio.run/##TcxNCoMwFATgfU/yXrBtfkmyeN7AQ4SiraWkokEUcvdUF4XALL6ZxbzDGpbHPE7puroyUInUQk9dSK/b5/sUHCJm3mwU77CT4Iz12OwMYGvJIDM5n5LIZM4CsUzzGBMMoBAvf5vKvrKWVbHSOyuqQVnnlTZHpNLH8w8 "JavaScript (V8) – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 15 bytes
```
T`3-9`225
\B.
0
```
[Try it online!](https://tio.run/##ZckrEoAwEARRP3eB2uynkrGcAYlIBAKDoLj/Ek/Xc/2c73WPzL3bwq4aOLYVklmgMAQIVzgRAhJFBFXZaoHVRvOY1Hy@Xx8 "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
T`3-9`225
```
Change `3` and `4` to `2`, and higher digits to `5`.
```
\B.
0
```
Change all digits after the first to `0`.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~13~~ ~~12~~ ~~10~~ 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
LR.ΔRTÑQO
```
-2 bytes by porting [*@JoKing*'s Raku answer](https://codegolf.stackexchange.com/a/210687/52210), so make sure to upvote him as well!  
-1 byte by taking inspiration from [*@Zgarb*'s second Husk answer](https://codegolf.stackexchange.com/a/210713/52210).
[Try it online](https://tio.run/##yy9OTMpM/f/fJ0jv3JSgkMMTA/3//zexBAA) or [verify almost all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXLoZX/fYL0zk0JCjk8MdD/f63O/2hDHSMdYx1THUsdEyMdE0sdUwMdS0sdQwMDHTNzCx1zI0sL81gA) (times out for the larger test cases).
**Explanation:**
```
L          # Push a list in the range [1, (implicit) input-integer]
 R         # Reverse it
  .Δ       # Find the first value which is truthy for:
    R      #  Reverse the integer
           #   i.e. 200 → "002"
     T     #  Push 10
      Ñ    #  Pop 10 and push its divisors: [1,2,5,10]
       Q   #  Check for each if it's equal to the reversed integer
           #   "002" → [0,1,0,0]
        O  #  Take the sum of those checks (only 0 or 1 will be truthy at a time,
           #  and 10 is never truthy because no integer had leading 0s)
           # (after which the result is output implicitly)
```
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), ~~78 69~~ 66 bytes
```
-[<+>>+>+<<-----],++<[->-<]>[-[-[-[>+++<[-]]]]>+<]>--.>--->,[<.>,]
```
[Try it online!](https://tio.run/##HYpBCoAwEAMftE0PtqLCko8se1BBEMGD4PvX2knmErI963kf735FwFRIoajix5OIGgh1GnooffJGuzmB3ASTaWbyiDLNS6lj61DqBw "brainfuck – Try It Online")
-9 bytes by rearranging the variables and adding the output directly to the ASCII value.
-3 bytes by calculating and triplicating the constants in a single loop
```
[tape: 51, input (of first digit), output + 51, 51, input (of other digits)]
-[<+>>+>+<<-----]       51 0 51 51
,++<[->-<]              input minus 49("1")
>[                      if not input = 1
  -[-[-[                    if not input between 2 and 4
    >+++                        add 3 to output (will add another 1 later)
    <[-]                        set input = 0 
  ]]]                       exit if
  >+<                       inc output ("4" if input between "2" and "4" | "7" if input not between "1" and "4")
]
>--.                    decrement output by 2 and print it
>---                    set third 51 to 48("0")
>,[                     while more characters in input
  <.>                       print "0"
  ,                         read next input char
]
```
[Answer]
# [Rockstar](https://codewithrockstar.com/), ~~163~~ ... ~~119~~ ~~117~~ 97 bytes
```
listen to N
cut N
roll N in D
X's 5
until X's as low as D
let X be/2
turn down X
say X*10*N or X
```
[Try it](https://codewithrockstar.com/online) (Code will need to be pasted in)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 45 bytes
```
Max@Select[{1,2,5}10^⌊Log10[s=#]⌋,#<=s&]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773zexwiE4NSc1uSS62lDHSMe01tAg7lFPl09@uqFBdLGtcuyjnm4dZRvbYrVYtf8BRZl5JQr6Dun6DmDVxjqmOpY6JkY6JpY6pgY6lpY6hgYGOuZGlhbmhjrG5haWxiamQGRkbAKUQwe1//8DAA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~40 39~~ 32 bytes
```
f(n){n=n>9?10*f(n/10):5>>5/-~n;}
```
[Try it online!](https://tio.run/##dVHNboMwDL7zFBZSJaBBhJ@IMgY7THuKwaGC0CFtoSIc0BB7dWYCbam6WXGSz/4cO3Zhn4pimipDmINIRBq9uNRC5LjUfGJpyhz7R8TjVIsOvo61MExt0ABlNnRcdvI9hwQGl4BHwCfACEQEAgQBnowixNOleAm96BC6YwyOBV3TwGcjTlA1rXoLg8ND5AcMl@cHc9iDYKjlXLPz/syLjpfbAjxVAC6PLspWVQUwOgv5pwLkb@TCvpNbAcXHsbWgXXLrWf/mZX30isp0Alvs62OsqZA5jzEnqkXJe4yj8Xp9Bll/86YyVENNZ0XWAmPY7xXPhKX1lwYIfGMZgXLn8Z2Xo/faor8IEgnz3G/Wc4v2ytB3Jdgp4L6TmcD/CAKS4GdlkvB85Y/aOP0C "C (gcc) – 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\$ using [xnor](https://codegolf.stackexchange.com/users/20260/xnor)'s [formula](https://codegolf.stackexchange.com/a/210684/9481).
[Answer]
# [sed 4.2.2](https://www.gnu.org/software/sed/), 25
* Thanks to @David258 for suggesting the use of `2g` to start replacing at the 2nd match and saving a byte.
Pretty much the same as the [perl answer](https://codegolf.stackexchange.com/a/210701/11259). Sadly the sed `y` command is not as flexible.
```
s/./0/2g
y/346789/225555/
```
[Try it online!](https://tio.run/##XYqxEYAwDMT6HwY7b5vE@8AxQCqmN67RqZP2fVVtOUSFD14xP@dKIaORqgHCEEg44YlQZGKoYjLXHLDezaOlebc/Hw "sed 4.2.2 – Try It Online")
[Answer]
# [Brain-Flak](https://github.com/Flakheads/BrainHack), 116 bytes
```
({}<<>(((((()()()){}){}){}){})<>{{}<>(({}))<>}>)({}<>[({})<((((((((({}<>())())))()()())))))>[]]){({}()<{}>)}{}({}<>)
```
[Try it online!](https://tio.run/##RUy7CoAwDPwXp94gVJ2EEPA7SofqoggOrqHfHpOieMlwxz3WuxzXXrZTNUgl4tAAP0j9n1jMN9u4icrwPCfXFD60CLwLvCMOTjlDzA0gsWo15lGoar9oNw/jFGPsHg "Brain-Flak (BrainHack) – Try It Online")
This uses string IO. Meaning input is expected as a string and output is produced as a string. This works by replacing all the digits other than the lead with zeros and then mapping the lead to the three results.
Rather predictably for Brain-Flak the two biggest sinks are
1. Producing the ascii code for `0`
2. Mapping 9 different values to arbitrary outputs.
The first part which replaces everything with zeros is:
```
({}<<>(((((()()()){}){}){}){})<>{{}<>(({}))<>}>)
```
With most of it being the code for point 1:
```
(((((()()()){}){}){}){})
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 25 bytes
```
@(_<=aFI[5 2o]*t**(#a-1))
```
A simple solution with filtering.
## Explanation
```
@(_<=aFI[5 2o]*t**(#a-1))
               t**(#a-1)  ten to the power (length of input - 1) 
        [5 2o]*           times the list [5,2,1]
  _<=aFI                  Filtered by lambda: element <= input?
@(                      ) first element of filtered list
```
[Try it online!](https://tio.run/##K8gs@P/fQSPexjbRzTPaVMEoP1arREtLQzlR11BT8////5aYAAA "Pip – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 43 bytes
```
@(x)y((y=[5 2 1]*10^floor(log10(x)))<=x)(1)
```
[Try it online!](https://tio.run/##dVBNS8QwEL37K@YiNOKWpB@kAQv@AI/eRCHtTrZZY1PaZN3@@tqkHgqrQ3iZzLx5b4htnbzgouo0TZfn5ErmJJnrtxIyYO8PjH4oY@2YGHtidO0S8lRfScLIola4U0kWIA9QBhABilgsYl7SWI45o/HBM1HxOJzzSuRFuZ4sLyKPUs6EyMqCF3S9CdzDixxPODno/VeDI7hOOhjRaNmYGb7t@DnBAY4ewVkYRmz1pG0PVsHR@sZgGu33UVa5@E9Yts5LsxM@@5XRyWHAfgoODYL8Vd4mNmKvWzTzrVeI4PXa6QmU1Ga6XfUA@z/@Y57UG4Hx9LZZM/4IjXeAF2m8dBjXZNXyAw "Octave – Try It Online")
This converts the number to the highest power of 10 less than the number, then multiplies by 5, 2, and 1 to get the possible notes that could be involved. It then finds the largest note still less than the number.
---
It should be noted that Octave is very doubley and not really friends with 64bit integers. As a result numbers larger than 2^53 don't reliably work due to double precision issues. This may invalidate the answer.
---
---
The below answer is valid only if it is allowed to take the input as a string, and return a string, overcoming the double precision issues.
# [Octave](https://www.gnu.org/software/octave/), 41 bytes
```
@(x,y='521')[y(x(1)>=y)(1) 48+x(2:end)*0]
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0Kn0lbd1MhQXTO6UqNCw1DTzrZSE0gpmFhoV2gYWaXmpWhqGcT@T9NQB6rhAlJGEMoYQplCKEsIZQKVNIHyTQ2g0lC@oQFUwNzI0sIcaqCxuYWlsYkpEBkZm8DUowN1zf8A "Octave – Try It Online")
[Answer]
# JavaScript, ~~30~~ 29 bytes
I/O as an array of digits.
Uses xnor's formula for the first digit so please be sure to upvote him if you're upvoting this.
```
a=>a.map((x,y)=>y?0:5>>5/-~x)
```
[Try it online!](https://tio.run/##ZY5LCoMwFAD3PYVkldBnGvNBU0h6EBEM0hTFGtEicePVU@m2w@xnBre5tVv6@ZNvVfImOWMdfbsZ4wg7MXZ/sLuyVt3yI5Lkw4JjFnxWF8BBgAINkoPUoBhoDQVjUHJdlQWIstJCqlMuJCD9B2rIpQvTGsYnHcMLe1xTSuMVoeY3EI09ziahQ@intiXpCw)
[Answer]
# [Bash](https://www.gnu.org/software/bash/), ~~39~~ 36 bytes
Saved 3 bytes thanks to [Digital Trauma](https://codegolf.stackexchange.com/users/11259/digital-trauma)!!!
```
echo $[(5>>5/-~${1::1})*10**~-${#1}]
```
[Try it online!](https://tio.run/##bY7haoMwFIX/@xRnWQYqyJJosGlR9h7WH5tGFErsGgcDsa/uoq6sYztcws13Lufet1fbzo0fYJx11faghS/zXD5HVzry/Z5PQchZGF4jOj7yqZwnb9B2sJnPIRBDQiERSBQkg1LgjCEVapdyxOlOxYl0JeLEeX8UePrzrKtB11uacGkSgi0l11rSJFvk2J2@4S8FXtNf0KEzIHR8WK8sXsqJHFD3HpxMRscN066cVqQduh3xQ21G/QbUBOvvfOnM0IA81YhyuJc4C9SuZtegKNxCTRDpd9dYgrI8DK02q38fcPwQKY@PhmyrT1b/O5JUt5Gm8@re6PkL "Bash – Try It Online")
Port of my [C answer](https://codegolf.stackexchange.com/a/210689/9481).
### Explanation:
```
echo $[(5>>5/-~${1::1})*10**~-${#1}]  
     $[                            ]   # Evaluate what's inside as an  
                                       #   arithmetic expression  
       (5>>                            # Shift 5 to the right by
           5/                          #   5 integally divided by
             -~                        #     1 plus
               ${1                     #      the first argument's
                  ::1})                #        substring starting at 0 of length 1   
                       *               # Times  
                        10**           #   10 to the power of   
                              ${#1}    #     the length of the first agument
                            ~-         #       minus 1
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 25 bytes
```
{≥.~×Ċ{~^h10}ᵗh∈125∧≜}ᵘot
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3wv/pR51K9usPTj3RV18VlGBoABadnPOroMDQyfdSx/FHnHKDAjPyS//@jDXWMdIx1THUsdUyMdEwsdUwNdCwtdQwNDGIB "Brachylog – Try It Online")
### How it works
```
{≥.~×Ċ{~^h10}ᵗh∈125∧≜}ᵘot
{                    }ᵘ   find all unique outputs of …
 ≥.                         the output is less-equal the input,
   ~×Ċ                      and two numbers which product is the output, where
      {~^h10}ᵗ                the 2. number can be obtained by 10^k,
              h∈125           the 1. number is one of 1, 2, 5
                   ∧≜       return the output with the constrains solved
                       ot order all possible banknotes and take the largest
```
[Answer]
# x86-16 machine code, IBM PC DOS, ~~34~~ ~~31~~ 30 bytes
```
00000000: d1ee ad8a c849 b830 0acd 10ac 3c35 7c04  .....I.0....<5|.
00000010: b035 eb07 3c32 b032 7d01 48cd 29c3       .5..<2.2}.H.).
```
Listing:
```
D1 EE       SHR  SI, 1          ; SI to DOS PSP 
AD          LODSW               ; AL = input length 
8A C8       MOV  CL, AL         ; input length into CL
49          DEC  CX             ; remove leading space from length
B8 0A30     MOV  AX, 0A30H      ; AH = 0AH, AL = '0' 
CD 10       INT  10H            ; display '0' CX number of times 
AC          LODSB               ; AL = first digit 
3C 35       CMP  AL, '5'        ; is it less than five? 
7C 04       JL   LT_FIVE        ; if so, check two 
B0 35       MOV  AL, '5'        ; otherwise it's a 5 spot 
EB 07       JMP  DONE           ; jump to display
        LT_FIVE: 
3C 32       CMP  AL, '2'        ; is it less than two? 
B0 32       MOV  AL, '2'        ; if not, it's a 2 
7D 01       JGE  DONE           ; jump to display 
48          DEC  AX             ; otherwise it's a '1'
        DONE:
CD 29       INT  29H            ; display first digit of denomination 
C3          RET                 ; return to DOS
```
[Try it online!](http://twt86.co/?c=0e6tishJuDAKzRCsPDV8BLA16wc8MrAyfQFIzSnD) (type `ASM 1`, `ASM 9`, etc)
Looks at the first digit and determines if it's less than `5` or `2` and resets it to the appropriate note digit. Then displays the remaining length of the input string as `0`'s.
Standalone PC DOS executable COM program. Input via command line, output to console.
[![enter image description here](https://i.stack.imgur.com/rzzf9.png)](https://i.stack.imgur.com/rzzf9.png)
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2) `t`, 5 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
ærTFƇ
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVDMyVBNnJURiVDNiU4NyZmb290ZXI9JmlucHV0PTcyOTg3MSZmbGFncz10)
Note: this is pretty slow (the 729871 case takes ~5s on my computer and ~10s on the online interpreter) because it checks every number in the range \$[1 .. \text{input}]\$.
#### Explanation
```
ærTFƇ  # Implicit input
æ      # Filter [1..input] by:
 r     #  Reverse it
  TF   #  Push the factors of 10
       #   -> [1, 2, 5, 10]
    Ƈ  #  And check if the reversed
       #  integer is in this list
       # Implicit output of last
       # (largest) integer
```
]