-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeup 2055.cpp
More file actions
65 lines (63 loc) · 928 Bytes
/
codeup 2055.cpp
File metadata and controls
65 lines (63 loc) · 928 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <algorithm>
#include <vector>
std::vector<int> min;
int main()
{
int num1, num2;
std::cin >> num1 >> num2;
int k = 0;
int count = 0;
int i = 1;
int j = 1;
if (num1 == 1 || num2 == 1)
{
min.push_back(1);
}
if (num1 == 2 || num2 == 2)
{
min.push_back(2);
}
do
{
if (i * i == num1)
{
min.push_back(i);
break;
}
else if (num1 % i == 0) {
min.push_back(i);
min.push_back(num1 / i);
i++;
}
else
{
if (i * i > num1) break;
i++;
}
} while (i <= num1/3);
do
{
if (j * j == num2)
{
min.push_back(j);
break;
}
else if (num2 % j == 0) {
min.push_back(j);
min.push_back(num2 / j);
j++;
}
else
{
if (j * j > num2) break;
j++;
}
} while (j <= num2 / 3);
sort(min.begin(), min.end());
min.erase(unique(min.begin(), min.end()), min.end());
for (int i = 0; i < min.size(); i++)
{
std::cout << min[i] << " ";
}
}