Created
May 16, 2023 04:17
-
-
Save Transfusion/f01d5de95a6e9b19c76b07dd6a2352ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def decompose(n): | |
res = None | |
ss = [] | |
def rec(squared, next_number_cannot_be_larger_than): | |
nonlocal res | |
if res: return | |
if squared == 0: | |
res = ss[::-1] | |
return | |
start_cond = min(int(math.sqrt(squared)), next_number_cannot_be_larger_than) | |
for i in range(start_cond, 0, -1): | |
if res: return | |
sq2 = i**2 | |
if squared >= sq2: | |
ss.append(i) | |
rec(squared - sq2, i-1) | |
ss.pop() | |
rec(n**2, n-1) | |
return res if res else None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment