CodeForces 515C. Drazil and Factorial

时间:2022-04-28 13:59:49
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 CodeForces 515C. Drazil and Factorial for positive integer x as a product of factorials of its digits. For example, CodeForces 515C. Drazil and Factorial.

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. CodeForces 515C. Drazil and Factorial = CodeForces 515C. Drazil and Factorial.

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, CodeForces 515C. Drazil and Factorial

真的说,这道题目是比较简单的,只是我的想法有点问题。

我做的过程太过于复杂了!在中间操作过程已经使结果超过 long long

而JS相当于在中间过程有简单的优化,是我没想到的,我把每个数还原的过于简单了

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <ctype.h>
using namespace std;
#define LL long long int main()
{
int n;
char num[];
int cnt[] = {};
int bit[];
while(scanf("%d%*c", &n) != EOF)
{
int tag = ;
for(int i = ; i < n; i++)
{
scanf("%c", &num[i]);
cnt[num[i] - '']++;
} for(int i = ; i < n; i++)
{
if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
}
sort(bit, bit+tag);
for(int i = tag-; i >= ; i--)
{
cout << bit[i];
}
cout << endl;
}
return ;
}