Guest User

Untitled

a guest
Jan 19th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import math
  2.  
  3. max_l = 0
  4. def check(coeffs, K, l):
  5.     if K == 0:
  6.         global max_l
  7.         max_l = max(max_l, l)
  8.         for i in range(1, min(3, l)+1):
  9.             # l - i + 1 terms
  10.             c = sum(coeffs[-j][0]*coeffs[-(l-i+2-j)][1] for j in range(1, l-i+2))
  11.             if c != 0:
  12.                 return
  13.  
  14.         print(coeffs)
  15.         return
  16.     B = sum(coeffs[i][0]*coeffs[-i][1] for i in range(1, l+1))
  17.     M = math.isqrt(K)
  18.     for bl1 in range(-M, M+1):
  19.         if (B - bl1) % 3 == 0:
  20.             bnl1 = (B - bl1) // 3
  21.             K_next = K - bl1*bl1 - bnl1*bnl1
  22.             if K_next >= 0:
  23.                 check([*coeffs, (bl1, bnl1)], K_next, l+1)
  24.  
  25.  
  26. check([(3, 1), (5, 0)], 0, 1)
  27. check([(3, 1), (-4, 3)], 0, 1)
  28. check([(3, 1), (2, 1)], 20, 1)
  29. check([(3, 1), (-1, 2)], 20, 1)
  30.  
  31. print(f"max l = {max_l}")
Advertisement
Add Comment
Please, Sign In to add comment