-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path백준-공약수.cpp.txt
94 lines (82 loc) · 1.17 KB
/
백준-공약수.cpp.txt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include<math.h>
using namespace std;
int m_max(int a, int b)
{
if (a > b)
return a;
else
return b;
}
int m_min(int a, int b)
{
if (a > b)
return b;
else
return a;
}
int main()
{
int num1, num2;
long long result1, result2;
result1 = 100000001;
result2 = 100000001;
cin >> num1 >> num2;
int high = m_max(num1, num2);
int low = m_min(num1, num2);
double ex = high / low;
double en = sqrt(ex);
int r = (int)ex;
int check = (int)en;
for (int i = 1; i <= check; i++)
{
if (r%i == 0)
{
long long A = num1 * i;
long long B = num1 * (r/i);
if (A + B < result1 + result2)
{
int c1 = -1;
int Big, Small;
if (A > B)
{
Big = A;
Small = B;
}
else
{
Big = B;
Small = A;
}
while (c1 != 0)
{
if (Big > Small)
{
}
else
{
int la = Big;
Big = Small;
Small = la;
}
c1 = Big % Small;
if (c1 == 0)
{
if (Small == num1)
{
result1 = A;
result2 = B;
}
break;
}
Big = c1;
}
}
}
else
{
}
}
cout << result1 << " " << result2 << endl;
return 0;
}