fork download
  1. from itertools import count
  2. for p in count(1):
  3. # checks if we are leaving room for 1/q + 1/r
  4. # 1/p >= 1/2
  5. if 2 >= p:
  6. continue # we need smaller values of 1/p
  7. # checks if we can reach 1/2 with the biggest legal values for 1/q and 1/r
  8. # 1/p + 1/p + 1/p < 1/2
  9. if 3 * 2 < p:
  10. break
  11. for q in count(p):
  12. # checks if we are leaving room for 1/r
  13. # 1/p + 1/q >= 1/2
  14. if 2 * (q + p) >= p * q:
  15. continue
  16. # checks if we can reach 1/2 with the biggest legal value for 1/r
  17. # 1/p + 1/q + 1/q < 1/2
  18. if 2 * (q + 2 * p) < p * q:
  19. break
  20. for r in count(q):
  21. lhs = 2 * (q * r + p * r + p * q)
  22. rhs = p * q * r
  23. # 1/p + 1/q + 1/r > 1/2
  24. if lhs > rhs:
  25. continue
  26. # 1/p + 1/q + 1/r < 1/2
  27. elif lhs < rhs:
  28. break
  29. # 1/p + 1/q + 1/r = 1/2
  30. else:
  31. print p, q, r
  32.  
Success #stdin #stdout 0.08s 8880KB
stdin
Standard input is empty
stdout
3 7 42
3 8 24
3 9 18
3 10 15
3 12 12
4 5 20
4 6 12
4 8 8
5 5 10
6 6 6