1.题目链接。给出一个正整数N(1<=N<=1e6),请给出N!在正整数下的唯一分解。
2.对于每一个素因子p,1-n中间是p的倍数的有 n/p个,然后考虑p^2,是n/p^2个。这样dp一下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 100;
int prime[maxx], ff[maxx];
int k;
void init(int n)
{
memset(ff, 0, sizeof(ff));
ff[1] = 1;
k = 0;
for (int i = 2; i <= n; i++) {
if (!ff[i]) {
prime[k++] = i;
for (int j = i + i; j <= n; j += i) {
ff[j] = 1;
}
}
}
}
int main()
{
int n;
scanf("%d", &n);
init(n);
for (int i = 0; i < k; i++) {
ll v = 0;
ll p = prime[i];
printf("%d ", p);
while (p <= n) {
v += n / p;
p *= prime[i];
}
printf("%d\n", v);
}
return 0;
}