Advertisement
serega1112

uporyad drobi

Jan 7th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. n = int(input())
  2. fractions = set()
  3.  
  4. for den in range(2, n+1):
  5.     for num in range(1, den):
  6.         a, b = num, den
  7.         while a % b > 0:
  8.             a, b = b, a % b
  9.         fractions.add(f'{num//b}/{den//b}')
  10.  
  11. res = sorted(list(fractions), key=lambda x: int(x.split('/')[0]) / int(x.split('/')[1]))
  12.  
  13. for elem in res:
  14.     print(elem)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement