Sums of two squares by rotary-o

val o=BigInt(1)
while(0<1)println{readLine
(Set(Seq(o*0,o))/:(readLine drop 2 split"\\D+"map(_.toLong)grouped 2)){(z,a)=>var s=z
var i,j,u,v,w=o
i=a(0)
j=a(1)
if(i>2)o to'a'find{k=>u=k.modPow(i/4,i)
v=i
while(v*v>i){w=u
u=v%u
v=w}
u>0}
if(i%4>2){j/=2
if(j<1)s=Set()
u=0
v=i}
for(_<-o to j)s=(s++s.map(_.reverse))map(b=>Seq((b(0)*v-b(1)*u)abs,b(0)*u+b(1)*v)sorted)
s}.toSeq sortBy(_(0))map(a=>a(0)+"^2 + "+a(1)+"^2")mkString" = "}

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