题目:
输入一个数N,计算N的阶乘的质因数的个数,按质数从小到大排列输出各个质数的个数。
Input:
测试用例的个数T(0<T<=100)
要求的数N(2<=N<=100)
输出:
N!的质因数的个数序列
如:
3
5
10
100
输出:
Case #1
3 1 1
Case #2
8 4 2 1
Case #3
97 48 24 16 9 7 5 5 4 3 3 2 2 2 2 1 1 1 1 1 1 1 1 1 1
代码如下:
#include<iostream>
using namespace std;
//#define DEBUG
int Prim[25] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
int Table[102] = { 0, };
void Init()
{
for (int i = 0; i < 25; i++)
Table[Prim[i]] = 1;
}
int Get(int n, int num)
{
if (n == 0) return 0;
else return Get(n / num, num) + n / num;
}
int main()
{
Init();
#ifdef DEBUG
freopen("Input.txt", "r", stdin);
setbuf(stdout, NULL);
#endif
int tc, T;
int N;
cin >> T;
for (int tc = 1; tc <= T; tc++)
{
cin >> N;
cout << "Case #" << tc << endl;
for (int j = 2; j <= N;j++)
{
if (Table[j] == 1)
{
int count = Get(N, j);
cout << count <<' ';
}
}
}
return 0;
}