Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- max_l = 0
- def check(coeffs, K, l):
- if K == 0:
- global max_l
- max_l = max(max_l, l)
- for i in range(1, min(3, l)+1):
- # l - i + 1 terms
- c = sum(coeffs[-j][0]*coeffs[-(l-i+2-j)][1] for j in range(1, l-i+2))
- if c != 0:
- return
- print(coeffs)
- return
- B = sum(coeffs[i][0]*coeffs[-i][1] for i in range(1, l+1))
- M = math.isqrt(K)
- for bl1 in range(-M, M+1):
- if (B - bl1) % 3 == 0:
- bnl1 = (B - bl1) // 3
- K_next = K - bl1*bl1 - bnl1*bnl1
- if K_next >= 0:
- check([*coeffs, (bl1, bnl1)], K_next, l+1)
- check([(3, 1), (5, 0)], 0, 1)
- check([(3, 1), (-4, 3)], 0, 1)
- check([(3, 1), (2, 1)], 20, 1)
- check([(3, 1), (-1, 2)], 20, 1)
- print(f"max l = {max_l}")
Advertisement
Add Comment
Please, Sign In to add comment