有些人心如花木,皆向阳而生
| 《剑来》
zz 很喜欢数学,但是他又是一个数学渣,我们称这种生物叫做学渣,
zz 又碰到了一个数学小问题,定义一个函数 P ( x )
例如: P (123) = 1! ∗ 2! ∗ 3! 现在需要找到的就是最大的大于等于 x 大的数 z 的函数值和 x 相等 ,
即 P ( z ) = P ( x ) 当然 z 这个数不能包含 1 或者 0
还请输出最大的符合要求 数 z(不一定比x大)
Input
第 1 行输入 T (1 ≤ T ≤ 20) 组数据
第 2 行输入 n (1 ≤ n ≤ 100) ,表示 x 的数字个数
第 3 行输入正整数 x
Output
输出最大的 z (数据保证 x 内含大于 1 的数,所以 z 必定有解) (z中不含1或0)
Sample Input
2 4 1234 3 555
Sample Output
33222 555
Hint
第一个样例f(1234) = 1! ∗ 2! ∗ 3! ∗ 4! = 288 = f(33222)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define pb push_back
int main() {
int T, n, x;
cin >> T;
while(T--) {
vector<int> v,vv;
string s;
cin >> n;
cin >> s;
for(int i = 0; i < n; ++i) {
x = s[i]-'0';
if(x == 9) {
v.pb(7); v.pb(3); v.pb(3); v.pb(2);
}
else if(x == 8) {
v.pb(7); v.pb(2); v.pb(2); v.pb(2);
}
else if(x == 6) {
v.pb(5); v.pb(3);
}
else if(x == 4) {
v.pb(3); v.pb(2); v.pb(2);
}
else if(x!=1&&x!=0)
v.pb(x);
}
sort(v.begin(), v.end(), greater<int>());
for(int i = 0; i < v.size(); ++i) {
cout << v[i];
}
cout << "\n";
}
return 0;
}