AcWing 1295. X的因子链
原题链接
中等
作者:
wjie
,
2020-07-04 11:39:37
,
所有人可见
,
阅读 668
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 105e4 + 5;
bool isPrime[N];
int prime[N], cnt;
long long factorial[25];
int factor[25];
void init()
{
isPrime[1] = true;
for (int i = 2; i < N; ++i)
{
if (!isPrime[i])
prime[cnt++] = i;
for (int j = 0; prime[j]*i < N; ++j)
{
isPrime[prime[j]*i] = true;
if (i % prime[j] == 0)
break;
}
}
factorial[0] = 1;
for (int i = 1; i <= 20; ++i)
factorial[i] = i * factorial[i-1];
}
int main()
{
init();
int n;
while (~scanf("%d", &n))
{
memset(factor, 0, sizeof(factor));
int idx = 0, tot = 0;
for (int i = 0; n > 1; ++i)
{
if (n % prime[i] == 0)
++idx;
while (n % prime[i] == 0)
{
tot++;
n /= prime[i];
factor[idx]++;
}
}
long long res = factorial[tot];
for (int i = 1; i <= idx; ++i)
res /= factorial[factor[i]];
printf("%d %lld\n", tot, res);
}
return 0;
}