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.
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 a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
4
1234
33222
3
555
555
In the first case,
自己先意淫2!~9!能被何数给表示(尽可能的使位数多)
可以发现
F(2)=F(2)
F(3)=F(3)
F(4)=F(322)
F(5)=F(5)
F(6)=F(53)
F(7)=F(7)
F(8)=F(7222)
F(9)=F(7332)
转换后将所有数排序输出即可。。比赛时大意地认为F(9)=F(733222),结果被hack,直降1000名。。。以后要格外认真才行
#include <iostream> #include <string.h> using namespace std; char res[20]; int main() { int a[10]; int b[10]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int n; cin>>n; cin>>res; for(int i=0;i<strlen(res);i++) { a[res[i]-'0']++; } for(int i=0;i<=9;i++) { if(a[i]!=0) { switch (i) { case 2: b[2]+=a[i]; break; case 3: b[3]+=a[i]; break; case 4: b[2]+=2*a[i]; b[3]+=a[i]; break; case 5: b[5]+=a[i]; break; case 6: b[5]+=a[i]; b[3]+=a[i]; break; case 7: b[7]+=a[i]; break; case 8: b[7]+=a[i]; b[2]+=3*a[i]; break; case 9: b[7]+=a[i]; b[3]+=2*a[i]; b[2]+=a[i]; break; } } } for(int i=9;i>=2;i--) { while (b[i]) { cout<<i; b[i]--; } } cout<<endl; return 0; }