Skip to content

Commit 2d6f375

Browse files
committed
[20260225] BOJ / G5 / 공약수 / 김민진
1 parent 7fc1469 commit 2d6f375

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_2436_공약수 {
6+
7+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
private static StringTokenizer st;
10+
11+
private static int gcd, lcm;
12+
private static long resA, resB;
13+
14+
public static void main(String[] args) throws IOException {
15+
init();
16+
sol();
17+
}
18+
19+
private static void init() throws IOException {
20+
st = new StringTokenizer(br.readLine());
21+
gcd = Integer.parseInt(st.nextToken());
22+
lcm = Integer.parseInt(st.nextToken());
23+
}
24+
25+
private static void sol() throws IOException {
26+
long div = lcm / gcd;
27+
28+
for (int i = 1; i <= Math.sqrt(div); i++) {
29+
if (div % i == 0) {
30+
long a = i;
31+
long b = div / i;
32+
33+
if (gcd(a, b) == 1) {
34+
resA = a;
35+
resB = b;
36+
}
37+
}
38+
}
39+
bw.write((resA * gcd) + " " + (resB * gcd));
40+
bw.flush();
41+
bw.close();
42+
br.close();
43+
}
44+
45+
private static long gcd(long a, long b) {
46+
while (b != 0) {
47+
long tmp = b;
48+
b = a % b;
49+
a = tmp;
50+
}
51+
52+
return a;
53+
}
54+
55+
}
56+
```

0 commit comments

Comments
 (0)