想了一段时间,最后从纯数学的角度上解决的。
首先读入这个串,因为素数是不可以被分解的,所以只要是素数,就整个的保留下来,如果是合数就分解成素数。
4!被分解为3!*2!*2!
6! = 5! * 3!
8! = 7! * 2! * 2! * 2!
9! = 7! * 3! * 3! * 2!
最后再用sort()反向排一下序,输出即可,碰到0和1跳过不管即可。
Description
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 Input
4 1234
33222
3 555
555
Hint
In the first case,
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<string.h>
using namespace std;
string str1;
string str2;
bool cmp(const char &a,const char &b)
{
return a > b;
}
int main()
{
// int str2[20];
// memset(str2 , 0 , sizeof(str2));
int n ;
cin>>n>>str1;
for(int i = 0 ; i < n ; i++)
{
// if(str[i] == '0')
// {
// cout<<'0'<<endl;
// break;
// }
if(str1[i] == '4')
str2 += "223";
else if(str1[i] == '6')
str2 += "53";
else if(str1[i] == '8')
str2 += "7222";
else if( str1[i] == '9')
str2 += "7332";
else if(str1[i] == '1');
else if(str1[i] == '0');
else
str2 += str1[i];
}
// cout<<str2<<endl;
sort(str2.begin(), str2.end() , cmp);
cout<<str2<<endl;
return 0;
}