> n) {//存储素数vector number;for (int i = 2; i number_all(n);for (int i = 0; i result;for (int i = 0; i。OJ|阶乘分解 kkmd66。" />
- 首页 > it技术 > >
#include
#include
#include "vector"using namespace std;
/**
* kkmd66 二刷
* @return
*/int main() {
int n;
while (cin >> n) {
//存储素数
vector number;
for (int i = 2;
i <= n;
++i) {
//判断是否为素数
bool flag = true;
for (int j = 2;
j <= sqrt(i);
++j) {
if (i % j == 0) {
flag = false;
break;
}
}
//添加
if (flag)
number.push_back(i);
}//存放阶乘
vector number_all(n);
for (int i = 0;
i < n;
++i) {
number_all[i] = i + 1;
}//依次相除,并存储
vector result;
for (int i = 0;
i < number.size();
++i) {
//计次
int count = 0;
for (int j = 0;
j < number_all.size();
++j) {
while (number_all[j] % number[i] == 0) {
number_all[j] /= number[i];
count++;
}
}
result.push_back(count);
}//输出
for (int i = 0;
i < result.size();
++i) {
if (i != result.size() - 1)
cout << result[i] << " ";
else
cout << result[i];
}
}
return 0;
}
推荐阅读