Advertisement
WadeRollins2710

Py

Dec 2nd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import sys
  2. import math
  3.  
  4. r = float(input())
  5. max_value = int(input())
  6. min_value = sys.maxsize
  7. for q in range(1, max_value + 1)[::-1]:
  8. t = r * q
  9. float_value = (int(t + 1)) / q
  10. if math.fabs(float_value - r) <= min_value:
  11. result_T = int(t + 1)
  12. result_Q = q
  13. min_value = math.fabs(float_value - r)
  14. float_value = (int(t)) / q
  15. if math.fabs(float_value - r) <= min_value:
  16. result_T = int(t)
  17. result_Q = q
  18. min_value = math.fabs(float_value - r)
  19. print(result_T, result_Q)
  20.  
  21. n = int(input())
  22. a = [0] * (n + 1)
  23. count = 0
  24. for i in range(1, n + 1):
  25. for j in range(2, n // i + 1):
  26. a[i * j] += i
  27. if (a[i] <= n) and (a[a[i]] <= n):
  28. if (i == a[a[i]]) and (i < a[i]):
  29. print(i, a[i])
  30. count += 1
  31. print("Result:", count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement