#pragma once
// x + yitemplate<typenameT>structGaussian_Integer{Tx,y;usingG=Gaussian_Integer;Gaussian_Integer(T_x=0,T_y=0):x(_x),y(_y){}Gaussian_Integer(constpair<T,T>&p):x(p.fi),y(p.se){}Tnorm()const{returnx*x+y*y;}Gconj()const{returnG{x,-y};}Goperator+(constG&r)const{returnG{x+r.x,y+r.y};}Goperator-(constG&r)const{returnG{x-r.x,y-r.y};}Goperator*(constG&r)const{returnG{x*r.x-y*r.y,x*r.y+y*r.x};}Goperator/(constG&r)const{Gg=G{*this}*r.conj();Tn=r.norm();g.x+=n/2,g.y+=n/2;returnG{g.x/n-(g.x%n<0),g.y/n-(g.y%n<0)};}Goperator%(constG&r)const{returnG{*this}-G{*this}/r*r;}G&operator+=(constG&r){return*this=G{*this}+r;}G&operator-=(constG&r){return*this=G{*this}-r;}G&operator*=(constG&r){return*this=G{*this}*r;}G&operator/=(constG&r){return*this=G{*this}/r;}G&operator%=(constG&r){return*this=G{*this}%r;}Goperator-()const{returnG{-x,-y};}Goperator+()const{returnG{*this};}booloperator==(constG&g)const{returnx==g.x&&y==g.y;}booloperator!=(constG&g)const{returnx!=g.x||y!=g.y;}Gpow(__int128_te)const{Gres{1},a{*this};while(e){if(e&1)res*=a;a*=a,e>>=1;}returnres;}friendGgcd(Ga,Gb){while(b!=G{0,0}){trc(a,b,a/b,a%b);swap(a%=b,b);}returna;}friendostream&operator<<(ostream&os,constG&rhs){returnos<<rhs.x<<" "<<rhs.y;}};
#line 2 "math/gaussian-integer.hpp"
// x + yitemplate<typenameT>structGaussian_Integer{Tx,y;usingG=Gaussian_Integer;Gaussian_Integer(T_x=0,T_y=0):x(_x),y(_y){}Gaussian_Integer(constpair<T,T>&p):x(p.fi),y(p.se){}Tnorm()const{returnx*x+y*y;}Gconj()const{returnG{x,-y};}Goperator+(constG&r)const{returnG{x+r.x,y+r.y};}Goperator-(constG&r)const{returnG{x-r.x,y-r.y};}Goperator*(constG&r)const{returnG{x*r.x-y*r.y,x*r.y+y*r.x};}Goperator/(constG&r)const{Gg=G{*this}*r.conj();Tn=r.norm();g.x+=n/2,g.y+=n/2;returnG{g.x/n-(g.x%n<0),g.y/n-(g.y%n<0)};}Goperator%(constG&r)const{returnG{*this}-G{*this}/r*r;}G&operator+=(constG&r){return*this=G{*this}+r;}G&operator-=(constG&r){return*this=G{*this}-r;}G&operator*=(constG&r){return*this=G{*this}*r;}G&operator/=(constG&r){return*this=G{*this}/r;}G&operator%=(constG&r){return*this=G{*this}%r;}Goperator-()const{returnG{-x,-y};}Goperator+()const{returnG{*this};}booloperator==(constG&g)const{returnx==g.x&&y==g.y;}booloperator!=(constG&g)const{returnx!=g.x||y!=g.y;}Gpow(__int128_te)const{Gres{1},a{*this};while(e){if(e&1)res*=a;a*=a,e>>=1;}returnres;}friendGgcd(Ga,Gb){while(b!=G{0,0}){trc(a,b,a/b,a%b);swap(a%=b,b);}returna;}friendostream&operator<<(ostream&os,constG&rhs){returnos<<rhs.x<<" "<<rhs.y;}};