C. Drazil and Factorial

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Drazil is playing a math game with Varda.

Let's define for positive integer x as a product of factorials of its digits. For example, .

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:

1. x doesn't contain neither digit 0 nor digit 1.

2. = .

Help friends find such number.

Input

The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.

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.

Output

Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.

Sample test(s)
Input
4
1234
Output
33222
Input
3
555
Output
555
Note

In the first case,

根据题目给出的数据可以猜到要么sqrt()简化数据,要么找规律;

其实就是将每个数字拆分为阶乘相乘形式,并且要求最大,由于2~9每个数字的阶乘相乘的形式是固定的,凡素数无法拆,此时答案就固定了;

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10    char str[][20]={"0","1","2","3","322","5","35","7","2227","2337"};//括号里面分别为0~9对应的阶乘相乘形式 比如6!=3!*5!
11    int n;
12    cin>>n;
13    char s[500]={"\0"},c[20];
14 
15    cin>>c;
16    for(int i=0;i<n;i++)
17    {
18        int m=c[i]-'0';
19        if(m>1) strcat(s,str[m]);
20    }
21 
22    int len=strlen(s);
23    sort(s,s+len);
24    for(int i=len-1;i>=0;i--)
25     cout<<s[i];
26    cout<<endl;
27 }

 

 

posted on 2015-02-18 18:13  wsa  阅读(197)  评论(0编辑  收藏  举报

导航