-
Notifications
You must be signed in to change notification settings - Fork 0
/
primeFactorial.cpp
55 lines (47 loc) · 928 Bytes
/
primeFactorial.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
class Solution{
public:
vector<int>AllPrimeFactors(int N) {
int i = 2;
vector<int> v;
while( i <= sqrt(N)){
if(N % i != 0){
i = i+1;
} else {
N = N/i;
if(v.size() == 0){
v.push_back(i);
} else {
if(v[v.size() - 1] != i){
v.push_back(i);
}
}
}
}
if(N > 1){
if(v.size()==0){
v.push_back(N);
} else {
if(v[v.size() - 1] != N){
v.push_back(N);
}
}
}
return v;
}
};
int main(){
int tc;
cin >> tc;
while(tc--){
long long int N;
cin >> N;
Solution ob;
vector<int>ans = ob.AllPrimeFactors(N);
for(auto i: ans)
cout << i <<" ";
cout <<"\n";
}
return 0;
}