Guest User

Untitled

a guest
Jun 27th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def wheel_235(n):
  2.  
  3.     # Removes all the factors 2, 3 and 5
  4.     for p in [2, 3, 5]:
  5.         if n % p == 0 and n > p:
  6.             n //= p
  7.             while n % p == 0:
  8.                 n //= p
  9.             if n == 1: return p
  10.  
  11.  
  12.     i = 0
  13.     # Iterates over all numbers not divisible
  14.     # by 2, 3, or 5
  15.     limit = int(n**0.5) + 1
  16.     while i < limit:
  17.         for k in [1, 7, 11, 13, 17, 19, 23, 29]:
  18.             if n % (i+k) == 0 and i+k > 1:
  19.                 n //= (i+k)
  20.                 while n % (i+k) == 0:
  21.                     n //= (i+k)
  22.                 if n == 1: return i+k
  23.                 limit = int(n**0.5) + 1
  24.         i += 30
  25.         # 2*3*5 = 30. We have already iterated over
  26.         # [1, 7, 11, 13, 17, 19, 23, 29]
  27.     return n
  28.  
  29. if __name__ == '__main__':
  30.     print wheel_235(600851475143)
Advertisement
Add Comment
Please, Sign In to add comment