Sums of two squares by mitchs (demo)

#!ruby -plropenssl
*r=k=1
eval(gets).map{|p,e|r=r.product(p<3?[(1+1i)**e]:p%4>1?[p**(e/2)]*(~e%2):(t=2;b=p
t+=1while-(a=t.to_bn.mod_exp(p/4,p).to_i)*a%p>1
a=b%b=a while b*b>p
(0..e).map{|i|(a+b*1i)**i*(a-b*1i)**(e-i)})).map{|x,y|x*y}}
$_=r.map{|x|x.rect.map(&:abs).sort}.sort.select{1>k^=1}.map{|x|x*'^2 + '+'^2'}*' = '

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

To protect the system from spam, please input your favorite sport (hint: I believe its name must start with 'g', case insensitive)

download

return to the top page