codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

515C.md (1611B)


      1 Source: https://codeforces.com/problemset/problem/515/C
      2 
      3 C. Drazil and Factorial
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Drazil is playing a math game with Varda.
     22 
     23 Let's define ![](https://espresso.codeforces.com/7020b94c48be2ee5b8eeca05f379c8911bb0e7c4.png) for positive integer *x* as a product of factorials of its digits. For example, ![](https://espresso.codeforces.com/6784d861d9a724d0aeddefcb00b7d0c3442ae586.png).
     24 
     25 First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
     26 
     27 1. *x* doesn't contain neither digit 0 nor digit 1.
     28 
     29 2. ![](https://espresso.codeforces.com/7020b94c48be2ee5b8eeca05f379c8911bb0e7c4.png) = ![](https://espresso.codeforces.com/aa57e017a6c74d06b0a54bc47e3f6990e5af38c1.png).
     30 
     31 Help friends find such number.
     32 
     33 Input
     34 
     35 The first line contains an integer *n* (1 ≤ *n* ≤ 15) — the number of digits in *a*.
     36 
     37 The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
     38 
     39 Output
     40 
     41 Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4  
     49 1234
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 33222
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 3  
     62 555
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 555
     69 ```
     70 
     71 Note
     72 
     73 In the first case, ![](https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png)