nullzero

Pro's square free

Jul 4th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import math
  2.  
  3. def lessthan(a, b, c, d):
  4.     """Is a/b < c/d?"""
  5.     return a * d < b * c
  6.  
  7. n = 10000000
  8. squares = {i * i for i in range(2, int(math.sqrt(n + 1)))}
  9. square_frees = [1 for i in range(n + 1)]
  10. for i in range(0, n + 1):
  11.     if i in squares and square_frees[i] == 1:
  12.         for j in range(i, n + 1, i):
  13.             square_frees[j] = 0
  14. square_frees[0] = 0
  15. a, b = 1000000000, 1
  16. A, B = 106, 176
  17. for i in range(1, n + 1):
  18.     square_frees[i] += square_frees[i - 1]
  19.     if lessthan(square_frees[i], i, a, b):
  20.         a, b = square_frees[i], i
  21.     #print("i = {}, ratio = {}".format(i, square_frees[i] / i))
  22.  
  23. print("lowest ratio: {}/{} = {} from i = {}".format(a, b, a / b, b))
  24. print("comparing with {}/{} = {}".format(A, B, A / B))
  25. if lessthan(a, b, A, B):
  26.     print("counterexample found")
  27. else:
  28.     print("no counterexample")
Add Comment
Please, Sign In to add comment