forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.rs
More file actions
69 lines (62 loc) · 1.41 KB
/
C.rs
File metadata and controls
69 lines (62 loc) · 1.41 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
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
use std::cmp::{min, max};
/// Scanner class
/// Copied from https://codeforces.com/contest/1168/submission/54903799
///
/// Usage:
/// ```
/// let mut scanner = Scanner::default();
/// let n = scan.next::<i32>();
/// ```
#[derive(Default)]
struct Scanner {
buffer: Vec<String>
}
impl Scanner {
fn next<T: std::str::FromStr>(&mut self) -> T {
loop {
if let Some(token) = self.buffer.pop() {
return token.parse().ok().expect("Failed parsing input")
}
let mut input = String::new();
std::io::stdin().read_line(&mut input).expect("Failed reading input");
self.buffer = input.split_whitespace().rev().map(String::from).collect();
}
}
}
/// Returns gcd(m, n).
/// gcd(0, 0) = 0
/// gcd(x, 0) = x
/// gcd(0, x) = x
fn gcd(mut m: i64, mut n: i64) -> i64 {
while n != 0 {
let t = m % n;
m = n;
n = t;
}
return m;
}
/// Returns lcm(m, n).
fn lcm(m: i64, n: i64) -> i64 {
return m / gcd(m, n) * n;
}
fn main() {
let mut scanner = Scanner::default();
assert_eq!(gcd(0, 0), 0);
assert_eq!(gcd(0, 10), 10);
assert_eq!(gcd(10, 0), 10);
let x = scanner.next::<i64>();
let mut res = x; // (x, 1)
let mut save_min = 1;
for a in 1..(1000 * 1000 + 1) {
if x % a == 0 {
let b = x / a;
if lcm(a, b) == x {
if max(a, b) < res {
res = max(a, b);
save_min = min(a, b);
}
}
}
}
println!("{} {}", res, save_min);
}