-
Notifications
You must be signed in to change notification settings - Fork 765
/
Copy pathprimefactors
43 lines (36 loc) · 932 Bytes
/
primefactors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//To count the number of prime factors of a number i.e. prime factorization for 12246 : 2*3*13*157
//so number of prime factors=4.
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001
long long spf[MAXN];
void sieve(){
spf[1] = 1;
for(long long i=2;i<MAXN;i++)
spf[i] = i;
for(long long i=4; i<MAXN; i+=2)
spf[i] = 2;
for(long long i=3;i*i<MAXN;i++){
if(spf[i]==i){
for (long long j=i*i; j<MAXN; j+=i)
if (spf[j]==j)
spf[j] = i;
}
}
}
vector<long long> getFactorization(long long x){
vector<long long> ret;
while (x != 1){
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
int main(int argc, char const *argv[]){
sieve();
long long n{0};
cin>>n;
vector <long long> p = getFactorization(n);
cout<<p.size()<<endl;
return 0;
}