解法一:暴力
限定分子分母的范围,然后依次判断是否互质。
class Solution {public List<String> simplifiedFractions(int n) {List<String> ans = new LinkedList<>();for (Integer i = 2; i <= n; ++i) {for (Integer j = 1; j < i; ++j) {if (judge(i, j)) {ans.add(j.toString() + '/' + i.toString());}}}return ans;}private boolean judge(int x, int y) {int tmp;while (y != 0) {tmp = y;y = x % y;x = tmp;}return (x == 1);}}
