-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLv.0-5.cpp
53 lines (46 loc) · 985 Bytes
/
Lv.0-5.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
#include <string>
#include <vector>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void isPrime(int n) {
bool chk;
for (int i = 2; i <= n; i++) {
chk = true;
for (int j = 2; j <= sqrt(i); j++) {
if (i % j == 0) {
chk = false;
break;
}
}
if (chk) {
prime.push_back(i);
}
}
}
vector<int> solution(int n) {
vector<int> answer;
isPrime(n);
int index = 0;
while (n != 1) {
if (n % prime[index] == 0) {
n = n / prime[index];
answer.push_back(prime[index]);
}
else {
index++;
}
}
answer.erase(unique(answer.begin(), answer.end()), answer.end());
return answer;
}
int main() {
int n;
cin >> n;
vector<int> sol = solution(n);
for (int i = 0; i < sol.size(); i++) {
cout << sol[i] << " ";
}
}