-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintallprimefactors.cpp
More file actions
50 lines (36 loc) · 870 Bytes
/
printallprimefactors.cpp
File metadata and controls
50 lines (36 loc) · 870 Bytes
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
#include <iostream>
using namespace std;
void f(int n, vector<int>&temp) {
for(int i = 2; i <= sqrt(n); i++) {
if(n%i == 0) {
temp.push_back(i);
while(n%i == 0)
n = n/i;
temp.push_back(i);
}
}
if(n != 1)temp.push_back(n);
}
vector<vector<int>> returnList(vector<int>&nums) {
vector<vector<int>> arr;
for(auto num : nums) {
vector<int>temp;
f(num, temp);
arr.push_back(temp);
}
return arr;
}
int main() {
vector<int> nums = {2,3,4,5,6,7,8,9};
vector<vector<int>> factors = returnList(nums);
cout << "\n[";
for(int i = 0; i < factors.size(); i++) {
cout << "[";
for(auto factor : factors[i]) {
cout << factor << ",";
}
cout << "]";
}
cout << "]\n\n";
return 0;
}