File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments