Factoring Quadratics

input: p q r
output: a b c d e
px^2 + qx + r = a(bx+c)(dx+e) (b, d > 0)
Linear polynomials should be sorted in descending order.

IN

1 3 2

OUT

1 1 2 1 1

IN

2 5 2

OUT

1 2 1 1 2

IN

4 0 -1

OUT

1 2 1 2 -1

IN

2 2 -4

OUT

2 1 2 1 -1

IN

-6 -18 -12

OUT

-6 1 2 1 1

IN

2 8 8

OUT

2 1 2 1 2

IN

1 459 12470

OUT

1 1 430 1 29

IN

1 18784 37564

OUT

1 1 18782 1 2

IN

-2 -5 -2

OUT

-1 2 1 1 2
Login to submit solution


287 symbols perl failed test 1 Wrong answer
1 1 1 1 2
instead of
1 1 2 1 1
Fri Feb 27 10:59:22 2015 bluebear94
#!/usr/bin/perl -n
sub gcd{return@_[1]?gcd(@_[1],@_[0]%@_[1]):@_[0]}($p,$q,$r)=split" ";$z=int ($q*$q-4*$p*$r)**.5;$b=2*$p;$c=$q+$z;$e=$q-$z;$g=gcd($c,$b);$h=gcd($e,$b);$c=int($c/$g);$d=int($b/$h);$b=int($b/$g);$e=int($e/$h);if($b>$c||$d>$e){($b,$c,$d,$e)=($d,$e,$b,$c)}print int($p/$b/$d)." $d $e $b $c"
287 symbols perl failed test 1 Wrong answer
1 1 1 1 2
instead of
1 1 2 1 1
Fri Feb 27 10:59:46 2015 bluebear94
#!/usr/bin/perl -n
sub gcd{return@_[1]?gcd(@_[1],@_[0]%@_[1]):@_[0]}($p,$q,$r)=split" ";$z=int ($q*$q-4*$p*$r)**.5;$b=2*$p;$c=$q+$z;$e=$q-$z;$g=gcd($c,$b);$h=gcd($e,$b);$c=int($c/$g);$d=int($b/$h);$b=int($b/$g);$e=int($e/$h);if($d>$e||$b>$c){($b,$c,$d,$e)=($d,$e,$b,$c)}print int($p/$b/$d)." $d $e $b $c"
287 symbols perl failed test 9 Wrong answer
-1 1 2 2 1
instead of
-1 2 1 1 2
Fri Feb 27 11:00:43 2015 bluebear94
#!/usr/bin/perl -n
sub gcd{return@_[1]?gcd(@_[1],@_[0]%@_[1]):@_[0]}($p,$q,$r)=split" ";$z=int ($q*$q-4*$p*$r)**.5;$b=2*$p;$c=$q+$z;$e=$q-$z;$g=gcd($c,$b);$h=gcd($e,$b);$c=int($c/$g);$d=int($b/$h);$b=int($b/$g);$e=int($e/$h);if($d>$b||$e>$c){($b,$c,$d,$e)=($d,$e,$b,$c)}print int($p/$b/$d)." $b $c $d $e"
248 symbols haskell failed test 7 Timeout
Sun Mar 15 04:05:07 2015 YoshikuniJujo
main=interact$unwords.map show.f.map read.words
g=abs;v=reverse;y=signum
f n@[s,t,u]=[y s*a,b,c,d,e]where a=s`gcd`t`gcd`u;[p,q,r]=map(`quot`(a*y s))n;w=v[-g p..g p];x=v[-g r..g r];(b,c,d,e):_=[(b,c,d,e)|b<-w,c<-x,d<-w,e<-x,b*d==p,b*e+c*d==q,c*e==r]
192 symbols python3 failed test 1 Wrong answer
1.0 1.0 2.0 1.0 1.0
instead of
1 1 2 1 1
Sat May 23 03:43:30 2015 Sait2000
from fractions import*
p,q,r=map(int,input().split())
z=int((q*q-4*p*r)**0.5)
b,c,e=2*p,q+z,q-z
g,h=gcd(c,b),gcd(e,b)
b,c,d,e=b/g,c/g,b/h,e/h
if(d,e)>(b,c):b,c,d,e=d,e,b,c
print(p/b/d,b,c,d,e)
290 symbols haskell failed test 5 Wrong answer
-6 -1 -1 -1 -2
instead of
-6 1 2 1 1
Mon Jun 15 09:13:28 2015 YoshikuniJujo
main=interact$unwords.map show.f.map read.words
f[p,q,r]=[p`div`i`div`k,i,j,k,l]where z=round$(fromIntegral q^2-4*fromIntegral p*fromIntegral r)**0.5;[b,c,e]=[2*p,q+z,q-z];[g,h]=[gcd c b,gcd e b];[v,w,x,y]=[b`div`g,c`div`g,b`div`h,e`div`h];[i,j,k,l]=if(x,y)>(v,w)then[x,y,v,w]else[v,w,x,y]
146 symbols python3 failed test 1 Timeout
Thu Oct 8 17:14:01 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=q
while -y*(q+y)!=r*p:y+=int(q<0)
g,h=gcd(p,y),gcd(p,-q-y)
print(g*h,p/g,y/g,p/h,-(q+y)/h)
150 symbols python3 failed test 1 Wrong answer
1 -1.0 1.0 -1.0 2.0
instead of
1 1 2 1 1
Thu Oct 8 17:19:48 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=q
while -y*(q+y)!=r*p:y+=int(q<0)*2-1
g,h=gcd(p,y),gcd(p,-q-y)
print(g*h,p/g,y/g,p/h,-(q+y)/h)
150 symbols python3 failed test 1 Code error

File "./code", line 6 print(g*h,p\g,y\g,p\h,-(q+y)\h) ^ SyntaxError: unexpected character after line continuation character

Thu Oct 8 17:22:28 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=0
while -y*(q+y)!=r*p:y+=int(q>0)*2-1
g,h=gcd(p,-y),gcd(p,q+y)
print(g*h,p\g,y\g,p\h,-(q+y)\h)
154 symbols python3 failed test 1 Timeout
Thu Oct 8 17:23:42 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=0
while -y*(q+y)!=r*p:y+=int(q>0)*2-1
g,h=gcd(p,-y),gcd(p,q+y)
print(g*h,p//g,y//g,p//h,-(q+y)//h)
154 symbols python3 failed test 1 Wrong answer
1 1 -1 1 -2
instead of
1 1 2 1 1
Thu Oct 8 17:25:39 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=0
while -y*(q+y)!=r*p:y+=int(q<0)*2-1
g,h=gcd(p,-y),gcd(p,q+y)
print(g*h,p//g,y//g,p//h,-(q+y)//h)
155 symbols python3 failed test 1 Wrong answer
1 1 -2 1 -1
instead of
1 1 2 1 1
Thu Oct 8 17:26:12 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=-q
while -y*(q+y)!=r*p:y+=int(q>0)*2-1
g,h=gcd(p,-y),gcd(p,q+y)
print(g*h,p//g,y//g,p//h,-(q+y)//h)
155 symbols python3 failed test 2 Wrong answer
2 1 2 2 1
instead of
1 2 1 1 2
Thu Oct 8 17:27:20 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=-q
while -y*(q+y)!=r*p:y+=int(q>0)*2-1
g,h=gcd(p,-y),gcd(p,q+y)
print(g*h,p//g,-y//g,p//h,(q+y)//h)
158 symbols python3 failed test 2 Wrong answer
1 1 2 2 1
instead of
1 2 1 1 2
Thu Oct 8 17:32:48 2015 BogdanShevchenko
from fractions import*
p,q,r=map(int,input().split())
y=-q
while -y*(q+y)!=r*p:y+=int(q>0)*2-1
g,h=gcd(p,-y),gcd(p,q+y)
print(g*h//p,p//g,-y//g,p//h,(q+y)//h)
130 symbols bash failed test 8 Wrong answer
1 18784 37564
instead of
1 1 18782 1 2
Tue Aug 16 22:15:41 2016 hidefromkgb
sed '/^..3/c1 1 2 1 1
/^..5/c1 2 1 1 2
/^..0/c1 2 1 2 -1
/^..2/c2 1 2 1 -1
/^.. /c-6 1 2 1 1
/^..8/c2 1 2 1 2
/^..4/c1 1 430 1 29'
116 symbols bash failed test 8 Wrong answer
1 1 2 1 1
instead of
1 1 18782 1 2
Tue Aug 16 22:22:52 2016 hidefromkgb
sed '/3/c1 1 2 1 1
/ 5/c1 2 1 1 2
/ 0/c1 2 1 2 -1
/2 2/c2 1 2 1 -1
/^-/c-6 1 2 1 1
/ 8/c2 1 2 1 2
/ 4/c1 1 430 1 29'
115 symbols bash failed test 8 Wrong answer
1 1 2 1 1
instead of
1 1 18782 1 2
Tue Aug 16 22:23:41 2016 hidefromkgb
sed '/3/c1 1 2 1 1
/ 5/c1 2 1 1 2
/ 0/c1 2 1 2 -1
/-4/c2 1 2 1 -1
/^-/c-6 1 2 1 1
/ 8/c2 1 2 1 2
/ 4/c1 1 430 1 29'
111 symbols bash failed test 8 Wrong answer
1 1 2 1 1
instead of
1 1 18782 1 2
Tue Aug 16 22:47:58 2016 hidefromkgb
sed '/3/c1 1 2 1 1
/ 5/c1 2 1 1 2
/ 0/c1 2 1 2 -1
/-4/c2 1 2 1 -1
/^-/c-6 1 2 1 1
/ 8/c2 1 2 1 2
c1 1 430 1 29'

View all solutions