Guest User

Solution count for equation 1/x + 1/y = 1/n

a guest
Sep 14th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. from time import time
  2. st = time()
  3.  
  4. goal = 1000
  5. n = goal
  6. solutions = 0
  7.  
  8. while solutions <= goal:
  9.     solutions = 0
  10.     for x in range(n + 1, 2*n + 1):
  11.         y, rem = divmod(x * n, x - n)
  12.         if rem == 0:
  13.         if (x * n) % (x - n) == 0:
  14.             solutions += 1
  15.  
  16.     if n % 1000 == 0:
  17.         print('n = {:5}, solutions: {:4}, time is {:6.3f}'.format(n, solutions, time() - st))
  18.     n += 1
Advertisement
Add Comment
Please, Sign In to add comment