Minimal number of square

Input N - number. 0 <N < 90000.
Your task to find minimal number of square which together give the number N.


Example:
1) Input: 4. Answer: 1.
So, 4 = 2*2.
2) Input: 10. Answer: 2. 
10 = 3*3 + 1*1;
3) Input 14. Answer: 3.
14 = 3*3+2*2+1*1.

IN

344

OUT

3

IN

4

OUT

1

IN

10

OUT

2

IN

12

OUT

3

IN

7

OUT

4

IN

58509

OUT

3

IN

89968

OUT

4
Login to submit solution


13 symbols pyth
Sat Oct 29 17:31:20 2016 Sait2000
@`4432133%Q13
14 symbols pyth
Sat Oct 29 17:29:16 2016 Sait2000
@"4432133"%Q13
89 symbols python2
Sun Jul 24 14:15:19 2016 Sait2000
m=[0]
for _ in m*input():m+=~-max(m[-j*j]for j in range(-int(len(m)**.5),0)),
print-m[~0]
91 symbols python2
Sun Jul 24 14:12:33 2016 Sait2000
m=[0]
for _ in[0]*input():m+=~-max(m[-j*j]for j in range(-int(len(m)**0.5),0)),
print-m[-1]
92 symbols python2
Sun Jul 24 14:07:31 2016 Sait2000
m=[0]
for _ in[0]*input():m+=~-max(m[-j*j]for j in range(1,1+int(len(m)**0.5))),
print-m[-1]
94 symbols python2
Sat Jan 16 18:06:25 2016 Sait2000
m=[0]
for i in range(1,1+input()):m+=1+min(m[-j*j]for j in range(1,1+int(i**0.5))),
print m[i]
94 symbols python2
Sat Jan 16 18:06:47 2016 Sait2000
m=[0]
for i in range(1,1+input()):m+=1+min(m[-j*j]for j in range(1,1+int(i**0.5))),
print m[i]
95 symbols python2
Fri Jan 15 21:45:29 2016 Sait2000
m=[0]
for i in range(1,1+input()):m+=1+min(m[-j*j]for j in range(1,1+int(i**0.5))),
print m[-1]
95 symbols python3
Sat Oct 29 16:13:42 2016 Sait2000
m=[0]
for _ in m*int(input()):m+=-~min(m[-j*j]for j in range(-int(len(m)**.5),0)),
print(m[~0])
96 symbols python2
Tue Aug 18 20:17:52 2015 Sait2000
m=[0]
for i in range(1,1+input()):m+=[1+min(m[-j*j]for j in range(1,1+int(i**0.5)))]
print m[-1]
96 symbols pyth
Sat Oct 29 16:50:16 2016 Sait2000
ev%"eval('m.__iadd__(-~min(m[-j*j]%srange(-int(len(m)**.5),0))%sm*%s)',%s)"[J"for j in "JzXH\m]0
97 symbols pyth
Sat Oct 29 16:46:02 2016 Sait2000
ev%"eval('m.__iadd__(-~min(m[-j*j]for j in range(-int(len(m)**.5),0))for _ in m*%s)',{'m':[0]})"z
99 symbols perl
Fri Feb 27 10:10:02 2015 bluebear94
#!/usr/bin/perl -n
@m=(0);for$i(1..$_){$n=9;for$j(1..$i**.5){$p=$m[$i-$j*$j];$n=$p<$n?$p:$n}$m[$i]=$n+1}print$m[$#m]
100 symbols perl
Fri Feb 27 10:09:16 2015 bluebear94
#!/usr/bin/perl -n
@m=(0);for$i(1..$_){$n=9;for$j(1..$i**.5){$p=$m[$i-$j*$j];$n=$p<$n?$p:$n}$m[$i]=$n+1}print $m[$#m]
100 symbols pyth
Sat Oct 29 16:43:24 2016 Sait2000
v%"eval('m.__iadd__(-~min(m[-j*j]for j in range(-int(len(m)**.5),0))for _ in m*%s)[-1]',{'m':[0]})"z
101 symbols python2
Mon Feb 23 04:17:21 2015 Sait2000
m=[0]
for i in range(1,1+input()):m.append(1+min(m[-j*j]for j in range(1,1+int(i**0.5))))
print m[-1]
103 symbols pyth
Sat Oct 29 17:05:54 2016 Sait2000
=Y]0ev%"eval('Y.__iadd__(-~min(Y[-j*j]%srange(-int(len(Y)**.5),0))%sY*%s)',environment)"[J"for j in "Jz
105 symbols perl
Fri Feb 27 09:51:48 2015 bluebear94
#!/usr/bin/perl -n
@m=(0);for$i(1..$_){$n=9;for$j(1..sqrt($i)){$p=$m[$i-$j*$j];$n=$p<$n?$p:$n}$m[$i]=1+$n}print $m[$#m],$/
105 symbols pyth
Sat Oct 29 16:35:05 2016 Sait2000
 v%"exec('for _ in m*%s:m+=-~min(m[-j*j]for j in range(-int(len(m)**.5),0)),\\nprint(m[~0])',{'m':[0]})"z
105 symbols pyth
Sat Oct 29 16:42:11 2016 Sait2000
 v%"exec('m+=(-~min(m[-j*j]for j in range(-int(len(m)**.5),0))for _ in m*%s)\\nprint(m[~0])',{'m':[0]})"z

View all solutions