1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// @Title: 最简分数 (Simplified Fractions)
// @Author: 15816537946@163.com
// @Date: 2022-02-10 10:51:00
// @Runtime: 32 ms
// @Memory: 2.2 MB
// struct Solution;
impl Solution {
    pub fn simplified_fractions(mut n: i32) -> Vec<String> {
        let mut ret = Vec::new();

        fn back_track(i: i32, j: i32) -> i32 {
            return if i == 0 { j } else { back_track(j % i, i) };
        }
        (1..n).into_iter().for_each(|i| {
            (2..=n).into_iter().for_each(|j| {
                if i < j && back_track(i, j) == 1 {
                    ret.push(format!("{}/{}", i, j))
                }
            })
        });
        ret
    }
}