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


7 symbols python2 failed test 2 Wrong answer
3
instead of
1
Fri May 2 05:45:28 2014 nooodl
print 3
1 symbols php failed test 2 Wrong answer
3
instead of
1
Fri May 2 05:46:08 2014 nooodl
3
49 symbols perl failed test 1 Timeout
Fri Jun 13 19:18:06 2014 dionys
#!/usr/bin/perl -n
while($_){$i++;$_-=(int sqrt)^2 or last}print$i
41 symbols perl failed test 4 Wrong answer
4
instead of
3
Fri Jun 13 20:53:49 2014 dionys
#!/usr/bin/perl -pl
for(;$_;$i++){$_-=(int sqrt)**2}$_=$i
124 symbols python3 failed test 1 Timeout
Sat Aug 9 01:11:44 2014 z423x5c6
def f(a):
 return m([1+f(a-i*i)for i in range(1,int(a**.5))])
def m(a):
 if a:return min(a)
 return 0
print(f(int(input())))
167 symbols php failed test 1 Wrong answer
def f(a):
 if a in b:return b[a]
 c=1+m([f(a-i*i)for i in range(1,int(a**.5)+1)])
 b[a]=c
 return c
def m(a):
 return(min(a)if a else 0)
b={0:0}
print(f(int(input())))
instead of
3
Sat Aug 9 19:39:58 2014 z423x5c6
def f(a):
 if a in b:return b[a]
 c=1+m([f(a-i*i)for i in range(1,int(a**.5)+1)])
 b[a]=c
 return c
def m(a):
 return(min(a)if a else 0)
b={0:0}
print(f(int(input())))
20 symbols python2 failed test 4 Wrong answer
2
instead of
3
Wed Aug 13 02:28:19 2014 PFischbeck
print len(`input()`)
18 symbols python3 failed test 1 Code error

File "./code", line 1 printlen(input())) ^ SyntaxError: invalid syntax

Wed Aug 13 23:49:42 2014 vik
printlen(input()))
19 symbols python3 failed test 4 Wrong answer
2
instead of
3
Wed Aug 13 23:50:14 2014 vik
print(len(input()))
5 symbols python2 failed test 1 Code error

Traceback (most recent call last): File "./code", line 1, in <module> wc -m NameError: name 'wc' is not defined

Thu Aug 14 01:26:54 2014 PFischbeck
wc -m
5 symbols bash failed test 4 Wrong answer
2
instead of
3
Thu Aug 14 01:27:02 2014 PFischbeck
wc -m
11 symbols perl failed test 4 Wrong answer
2
instead of
3
Mon Aug 25 04:56:30 2014 gabrielmad
#!/usr/bin/perl -p
$_=length
9 symbols perl failed test 1 Wrong answer
1
instead of
3
Wed Aug 27 05:37:47 2014 gabrielmad
#!/usr/bin/perl -p
$_=/./g
10 symbols perl failed test 4 Wrong answer
2
instead of
3
Thu Sep 4 21:09:42 2014 gabrielmad
#!/usr/bin/perl -p
$_=y///c
138 symbols perl failed test 1 Code error

Semicolon seems to be missing at ./code line 2. Bareword found where operator expected at ./code line 6, near ") count" (Missing operator before count?) Can't modify constant item in scalar assignment at ./code line 3, near ") count " syntax error at ./code line 3, near ") count " Execution of ./code aborted due to compilation errors.

Tue Feb 24 16:40:40 2015 pyfreak
import math
n = float(raw_input())
count = 0
while n!=0:
        n = n-math.pow(math.floor(math.sqrt(n)),2)
        count +=1
print count
138 symbols python2 failed test 4 Wrong answer
4
instead of
3
Tue Feb 24 16:41:37 2015 pyfreak
import math
n = float(raw_input())
count = 0
while n!=0:
        n = n-math.pow(math.floor(math.sqrt(n)),2)
        count +=1
print count
199 symbols perl failed test 1 Code error

Undefined subroutine &main::zt called at ./code line 2, <STDIN> line 1.

Fri Feb 27 08:33:13 2015 bluebear94
#!/usr/bin/perl
$j=<STDIN>;@a=(0, 1);@y=(1);for $i(2 .. 90000) {$t=int(zt($i));if($t*$t==$i){$a[$i]=1;push @y,$i;next;}$c=100000;$m=0;for $z(@y){if($a[$i-$z]+1<=$c){$c=$a[$i-$z]+1;$m=$z;}}$a[$i]=$c;}print $a[$j],$/;
187 symbols perl failed test 1 Code error

Undefined subroutine &main::zt called at ./code line 2, <> line 1.

Fri Feb 27 08:35:22 2015 bluebear94
#!/usr/bin/perl -p
@a=(0,1);@y=(1);for $i(2..90000) {$t=int(zt($i));if($t*$t==$i){$a[$i]=1;push @y,$i;next;}$c=100000;$m=0;for $z(@y){if($a[$i-$z]+1<=$c){$c=$a[$i-$z]+1;$m=$z;}}$a[$i]=$c;}print $a[$_],$/;
187 symbols perl failed test 1 Code error

Undefined subroutine &main::zt called at ./code line 2, <> line 1.

Fri Feb 27 08:36:45 2015 bluebear94
#!/usr/bin/perl -p
@a=(0,1);@y=(1);for $i(2..90000){$t=int(zt($i));if($t*$t==$i){$a[$i]=1;push @y,$i;next;}$c=100000;$m=0;for $z(@y){if($a[$i-$z]+1<=$c){$c=$a[$i-$z]+1;$m=$z;}}$a[$i]=$c;}
print $a[$_],$/;
188 symbols perl failed test 1 Wrong answer
3
344
instead of
3
Fri Feb 27 08:39:25 2015 bluebear94
#!/usr/bin/perl -p
@a=(0,1);@y=(1);for $i(2..90000){$t=int(sqrt($i));if($t*$t==$i){$a[$i]=1;push @y,$i;next;}$c=100000;$m=0;for $z(@y){if($a[$i-$z]+1<=$c){$c=$a[$i-$z]+1;$m=$z;}}$a[$i]=$c;}print $a[$_],$/;

View all solutions