Files
python/TangDou/LanQiaoBei/LanQiao12GuoSai/GS12_2_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

42 lines
836 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/**
测试数据:12
参考答案:
2 2 3
3
*/
//埃拉筛
const int N = 1e5 + 10;
int primes[N], cnt; // primes[]存储所有素数
bool st[N]; // st[x]存储x是否被筛掉
void get_primes(int n) {
for (int i = 2; i <= n; i++)
if (!st[i]) {
//记录素数
primes[cnt++] = i;
//成倍数的标识
for (int j = 2 * i; j <= n; j += i) st[j] = true;
}
}
int main() {
int n;
cin >> n;
get_primes(n);
int c = 0;
for (int i = 0; i < cnt; i++) {
while (n % primes[i] == 0) {
n /= primes[i];
cout << primes[i] << " ";
c++;
}
}
cout << endl;
cout << c << endl;
return 0;
}