-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathCodeforces_1285C_Fadi_and_LCM.java
More file actions
42 lines (38 loc) · 1.08 KB
/
Codeforces_1285C_Fadi_and_LCM.java
File metadata and controls
42 lines (38 loc) · 1.08 KB
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
// AC: 358 ms
// Memory: 1900 KB
// 1.快捷求 LCM, 2.遍历从 sqrt(x) 到 1,只要有一个成功,那么 Max(i, x/i) 必然是最大值,直接return.
// T:O(sqrt(n) * log(n)), S:O(1)
//
import java.util.Scanner;
public class Codeforces_1285C_Fadi_and_LCM {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long x = sc.nextLong();
int sqrtX = (int) Math.sqrt(x);
long retA = 1, retB = 1;
for (long i = sqrtX; i >= 1; i--) {
if (x % i == 0 && getLCM(i, x / i) == x) {
retA = i;
retB = x / i;
break;
}
}
System.out.println(retA + " " + retB);
}
private static long getLCM(long a, long b) {
return a * (b / getGCD(a, b));
}
private static long getGCD(long a, long b) {
if (a > b) {
return getGCD(b, a);
}
if (a == 0) {
return b;
}
if (b % a == 0) {
return a;
} else {
return getGCD(b % a, a);
}
}
}