收藏
关注
X是一个n位数的正整数 (x=a0a1...an−1)
现在定义 F(x)=∏i=0n−1(ai!) , 比如F(135)=1!*3!*5!=720.
我们给定一个n位数的整数X(至少有一位数大于1,X中可能有前导0),
然后我们去找一个正整数(s)符合以下条件:
1.这个数尽可能大,
2.这个数中不能含有数字0或1。
3.F(s)=F(x)
Input
每个测试数据输入共2行。 第一行给出一个n,表示x为中数字的个数。(1<=n<=15) 第二行给出n位数的正整数X(X中至少有一位数大于1)
Output
共一行,表示符合上述条件的最大值。
Input示例
4 1234
Output示例
33222
看看每一个数可以分解为哪些数 处理一遍就可以了
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;
char ch[20];
int cnt[10];
int main() {
//FIN
int n;
while(~scanf("%d", &n)) {
memset(cnt, 0, sizeof(cnt));
scanf("%s", ch);
for(int i = 0; i < n; i++) cnt[ch[i] - '0']++;
int tmp = cnt[9];
cnt[3] += (tmp * 2);
cnt[2] += tmp;
cnt[7] += tmp;
cnt[9] = 0;
tmp = cnt[8];
cnt[7] += tmp;
cnt[2] += (tmp * 3);
cnt[8] = 0;
tmp = cnt[6];
cnt[5] += tmp;
cnt[3] += tmp;
cnt[6] = 0;
tmp = cnt[4];
cnt[3] += tmp;
cnt[2] += (tmp * 2);
cnt[4] = 0;
cnt[1] = 0;
cnt[0] = 0;
for(int i = 9; i >= 0; i--) {
if(cnt[i] == 0) continue;
for(int j = 1; j <= cnt[i]; j++) printf("%d", i);
}
printf("\n");
}
return 0;
}