Guest User

Untitled

a guest
Jan 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import math
  2.  
  3. N = 100 # fill in number of iterations
  4. G = 25 # fill in gcd(a,b)
  5.  
  6.  
  7. def binom(x, y):
  8. if y == x:
  9. return 1
  10. if y == 1:
  11. return x
  12. if y > x:
  13. return 0
  14.  
  15. a = math.factorial(x)
  16. b = math.factorial(y)
  17. c = math.factorial(x-y)
  18. return a // (b*c)
  19.  
  20.  
  21. def nextterm(a, gv):
  22. b = 0
  23. if a % 2 == 0: # even case
  24. for n in range(a//2 + 1):
  25. b += ((-1)**(n + (a // 2)) *
  26. binom(a//2 + n, a//2 - n) * gv**(4*n))
  27. else: # odd case
  28. for n in range((a-1)//2 + 1):
  29. b += ((-1)**(n + (a-1)//2) *
  30. binom((a-1)//2 + n+1, (a-1)//2 - n) * gv**(2 + 4*n))
  31. return b
  32.  
  33.  
  34. def quotient(a, b):
  35. return (a**2 + b**2) // (a*b + 1)
  36.  
  37.  
  38. for n in range(1, N+1):
  39. u = nextterm(n, G)
  40. v = nextterm(n-1, G)
  41. g = G
  42. j = (((math.sqrt(g**4 - 4) + g**2) / 2)**n *
  43. (g / (math.sqrt(g**4 - 4))) -
  44. (((-1 * (math.sqrt(g**4 - 4))) + g**2) / 2)**n *
  45. (g / (math.sqrt(g**4 - 4))))
  46.  
  47. print("------------- iteration %s -------------" % n)
  48. print("a_%d = %d" % (n-1, G*v))
  49. print("a_%d = %d" % (n, G*u))
  50. print("a*_%d = %d" % (n-1, j))
  51. print("k = %d" % quotient(G*u, G*v))
Add Comment
Please, Sign In to add comment