Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- N = 100 # fill in number of iterations
- G = 25 # fill in gcd(a,b)
- def binom(x, y):
- if y == x:
- return 1
- if y == 1:
- return x
- if y > x:
- return 0
- a = math.factorial(x)
- b = math.factorial(y)
- c = math.factorial(x-y)
- return a // (b*c)
- def nextterm(a, gv):
- b = 0
- if a % 2 == 0: # even case
- for n in range(a//2 + 1):
- b += ((-1)**(n + (a // 2)) *
- binom(a//2 + n, a//2 - n) * gv**(4*n))
- else: # odd case
- for n in range((a-1)//2 + 1):
- b += ((-1)**(n + (a-1)//2) *
- binom((a-1)//2 + n+1, (a-1)//2 - n) * gv**(2 + 4*n))
- return b
- def quotient(a, b):
- return (a**2 + b**2) // (a*b + 1)
- for n in range(1, N+1):
- u = nextterm(n, G)
- v = nextterm(n-1, G)
- g = G
- j = (((math.sqrt(g**4 - 4) + g**2) / 2)**n *
- (g / (math.sqrt(g**4 - 4))) -
- (((-1 * (math.sqrt(g**4 - 4))) + g**2) / 2)**n *
- (g / (math.sqrt(g**4 - 4))))
- print("------------- iteration %s -------------" % n)
- print("a_%d = %d" % (n-1, G*v))
- print("a_%d = %d" % (n, G*u))
- print("a*_%d = %d" % (n-1, j))
- print("k = %d" % quotient(G*u, G*v))
Add Comment
Please, Sign In to add comment