# Give you an integer n , Please return to all 0 To 1 Between ( barring 0 and 1) Satisfy that the denominator is less than or equal to n Of Simplest fraction . The score can be in the form of arbitrarily Sequential return .
#
#
#
# Example 1:
#
# Input :n = 2
# Output :["1/2"]
# explain :"1/2" Is the only denominator less than or equal to 2 The simplest fraction of .
#
# Example 2:
#
# Input :n = 3
# Output :["1/2","1/3","2/3"]
#
#
# Example 3:
#
# Input :n = 4
# Output :["1/2","1/3","1/4","2/3","3/4"]
# explain :"2/4" It's not the simplest fraction , Because it can be reduced to "1/2" .
#
# Example 4:
#
# Input :n = 1
# Output :[]
#
#
#
#
# Tips :
#
#
# 1 <= n <= 100
#
# Related Topics mathematics character string number theory 42 0
# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
def gcd(self, a, b):
return a if b == 0 else gcd(b, a % b)
def simplifiedFractions(self, n: int) -> List[str]:
ret = []
for i in range(2, n + 1):
for j in range(1, i):
if gcd(i, j) == 1:
ret.append("{}/{}".format(j, i))
return ret
# leetcode submit region end(Prohibit modification and deletion)
This question should ask for t
(0) Abstract # Course link : n
Authors brief introduction : H