Advertisement
cicwak

Untitled

Sep 10th, 2022
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. def four_squares(number: int) -> list[int, int, int, int]:
  5.  
  6.  
  7.     limit_ = math.ceil(math.sqrt(number))
  8.  
  9.     for a in range(limit_, -1, -1):
  10.         if a ** 2 <= number:
  11.             limit = math.ceil(math.sqrt(number - a ** 2 + 1))
  12.             for b in range(limit, -1, -1):
  13.                 if a ** 2 + b ** 2 <= number:
  14.                     limit = math.ceil(math.sqrt(number - a ** 2 - b ** 2 + 1))
  15.                     for c in range(limit, -1, -1):
  16.                         if a ** 2 + b ** 2 + c ** 2 <= number:
  17.                             limit = math.ceil(math.sqrt(number - a ** 2 - b ** 2 + 1 - c ** 2))
  18.                             for d in range(limit, -1, -1):
  19.                                 # print([a, b, c, d])
  20.                                 if a ** 2 + b ** 2 + c ** 2 + d ** 2 == number:
  21.                                     return [a, b, c, d]
  22.  
  23.  
  24. print(four_squares(106369249365575352836589875696130383747))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement