-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1447.rs
32 lines (30 loc) · 871 Bytes
/
p1447.rs
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
use crate::lc::Solution;
/// #format!
impl Solution {
pub fn simplified_fractions(n: i32) -> Vec<String> {
fn exist_common_divisor(m: i32, n: i32) -> bool {
for k in 2..=m {
if m % k == 0 && n % k == 0 {
return true;
}
}
false
}
let mut res = vec![];
for i in 2..=n {
for j in 1..i {
if j > 1 && exist_common_divisor(j, i) {
continue;
}
res.push(format!("{}/{}", j, i));
}
}
res
}
}
#[test]
fn test() {
assert_eq!(vec!["1/2"], Solution::simplified_fractions(2));
assert_eq!(vec!["1/2","1/3","2/3"], Solution::simplified_fractions(3));
assert_eq!(vec!["1/2","1/3","2/3","1/4","3/4"], Solution::simplified_fractions(4));
}