您的位置:首页 > 其它

CodeForces 515C. Drazil and Fa

2015-06-10 11:51 411 查看
想了一段时间,最后从纯数学的角度上解决的。

首先读入这个串,因为素数是不可以被分解的,所以只要是素数,就整个的保留下来,如果是合数就分解成素数。

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

Input
4
1234


Output
33222


Input
3
555


Output
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: