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


61 symbols pyth
Thu Nov 3 19:07:50 2016 Sait2000
.vCim-id64^964 2cCM"矴㢿㲺痍蠂蓇㟖亼盍宻堃䶽毛瘄蟂㟄㟖㋂蟂壍瀉瘊盍暽壚濲澾篯悼㳢咼濞㳢喼濩"3^4 8
63 symbols pyth
Thu Nov 3 18:05:30 2016 Sait2000
.vCim-id64^964 2cCM"挺Ⲛ㏫栣딤饖뼀혳ᗤ缃勽嵒〱仯뢡䭚ꑱ뒁빒쩏⳦옓좪袪塙씑醇❰曯ᚇ䜛"3 65955
69 symbols pyth
Thu Nov 3 17:57:44 2016 Sait2000
jd+//*h=rz7*FA,i=N+Js@-^Khtz2*4*F%2z2K=byhzi=Y-KJbbb.n_S,/RG,bN/RH,bY
71 symbols pyth
Thu Nov 3 10:52:16 2016 Sait2000
=rz7Js@-^Khtz2*4*F%2z2jd+//*hz*FA,i=N+KJ=byhzi=Y-KJbbb.n_S,/RG,bN/RH,bY
73 symbols pyth
Thu Nov 3 10:40:57 2016 Sait2000
=rz7Js@-^Khtz2*4*F%2z2jd+//*hz*FA,i=N+KJ=byhzi=Y-KJbbb.n_S,,/bG/NG,/bH/YH
194 symbols python2
Thu Nov 3 16:58:25 2016 Sait2000
from fractions import*
p,q,r=map(int,raw_input().split())
z=int((q*q-4*p*r)**.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
195 symbols python2
Sun Feb 22 12:54:17 2015 Sait2000
from fractions import*
p,q,r=map(int,raw_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
249 symbols haskell
Wed Jun 17 07:18:46 2015 YoshikuniJujo
(!)=div
d=fromIntegral
main=interact$unwords.map show.f.map read.words
f[p,q,r]=[p!i!k,i,j,k,l]where z=round$(d q^2-4*d p*d r)**0.5;b=2*p;c=q+z;e=q-z;s=signum p;g=gcd c b*s;h=gcd e b*s;v=b!g;w=c!g;x=b!h;y=e!h;(i,j)=max(x,y)(v,w);(k,l)=min(x,y)(v,w)
307 symbols haskell
Mon Jun 15 09:23:57 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*signum p,gcd e b*signum p];[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]

View all solutions