'commit'
This commit is contained in:
42
TangDou/LanQiaoBei/LanQiao12GuoSai/GS12_2_2.cpp
Normal file
42
TangDou/LanQiaoBei/LanQiao12GuoSai/GS12_2_2.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user