fork(1) download
  1. A=abs
  2. R=lambda z:round(z.real)+round(z.imag)*1j
  3. def G(a,b):
  4. if A(a)<A(b):a,b=b,a
  5. return G(b,r)if(r:=a-R(a/b)*b)else b
  6. def C(n):
  7. a=[];N=int(A(n)**2);s=[1>0]*N;s[0]=s[1]=F=1>1;s[4::2]=[F]*(N-3>>1)
  8. for i in range(3,-~int(N**.5)):
  9. if s[i]:s[i*i::2*i]=(~-N+i*(2-i))//2//i*[F]
  10. for p in[i for i,v in enumerate(s)if v]:
  11. while N%p<1:N//=p;a+=p,
  12. F,P,*z=a,1
  13. while[]<F:
  14. if(a:=F.pop(0))==2:u=1+1j
  15. if a%4>2:u=a;F.pop(0)
  16. else:
  17. while P<a!=-~pow(P:=P+1,~-a//2,a):1
  18. u=t-t.imag*2jif A(n-R(n/(t:=G(a,pow(P,~-a//4,a)+1j)))*t)else t
  19. n/=u;z+=R(u),
  20. return z[:-1]+[z[-1]*R(n)]
  21.  
  22. print(C(6840+585j))
  23.  
Success #stdin #stdout 3.7s 750148KB
stdin
Standard input is empty
stdout
[(3+0j), (3+0j), (2+1j), (-1-2j), (4-1j), (6+1j), (-1+6j)]