题目
题目链接:http://codeforces.com/problemset/problem/515/C
题目来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105944#problem/D
简要题意: F(n) 为各位的阶乘之积,求一最大的 n′,F(n′)=F(n) 。
题解
数学题,分情况去讨论或者一步步分解。
首先对于质数或 1 <script type="math/tex" id="MathJax-Element-3">1</script>的阶乘是无法分解的。
能够分解成越多数字越好,然后就去分解就行了,都是分解成若干质数。
代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
// head
int cnt[15];
char s[25];
void add(int x) {
if (x == 0 || x == 1) return;
if (x==2 || x==3 || x==5 || x== 7) {
cnt[x]++;
} else if (x == 4) {
cnt[2] += 2, cnt[3]++;
} else if (x == 6) {
cnt[5]++, cnt[3]++;
} else if (x == 8) {
cnt[7]++, cnt[2] += 3;
} else {
cnt[7]++, cnt[2]++, cnt[3] += 2;
}
}
int main() {
int n;
scanf("%d%s", &n, s);
for (int i = 0; i < n; i++) {
add(s[i] - '0');
}
for (int i = 9; ~i; i--) {
while (cnt[i]--) putchar(i + '0');
}
puts("");
return 0;
}