PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from math import sqrt
from itertools import combinations_with_replacement as cb
n = int(input())
print(n, end=" = ")
mx = sqrt(n)
if mx == int(mx):
print(mx, end="**2")
else:
sn = [i for i in range(1, int(mx)+1)]
i = 2
c = True
while c:
for j in cb(sn, i):
if sum(map(lambda x: x**2, j)) == n:
factors = j
c = False
break
i += 1
print(*factors[::-1], sep="**2 + ", end="**2")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run