## HHHOJ #153. 「NOI模拟 #2」Kotomi

$$a,b$$均为整数时，它其实是个高斯整数的形式，那么我们可以把带余除法推广到高斯整数环

#include<cstdio>
#include<iostream>
#define int long long
#define RI register int
#define CI const int&
using namespace std;
const int N=100005;
inline int Fix(int x,int y)
{
int f=1; if (x<0) x=-x,f=-1; return (x%y*2<y)?((x/y)*f):((x/y+1)*f);
}
struct Complex
{
int x,y;
inline Complex(CI X=0,CI Y=0)
{
x=X; y=Y;
}
friend inline Complex operator + (const Complex& A,const Complex& B)
{
return Complex(A.x+B.x,A.y+B.y);
}
friend inline Complex operator - (const Complex& A,const Complex& B)
{
return Complex(A.x-B.x,A.y-B.y);
}
friend inline Complex operator * (const Complex& A,const Complex& B)
{
return Complex(A.x*B.x-A.y*B.y,A.y*B.x+A.x*B.y);
}
friend inline Complex operator / (const Complex& A,const Complex& B)
{
Complex iB=Complex(B.x,-B.y),ret=A*iB; int dv=B.x*B.x+B.y*B.y;
return Complex(Fix(ret.x,dv),Fix(ret.y,dv));
}
friend inline Complex operator % (const Complex& A,const Complex& B)
{
return A-((A/B)*B);
}
}a[N],g; int n,mix,mxx,miy,mxy;
inline Complex gcd(const Complex& A,const Complex& B)
{
//printf("%lld %lld %lld %lld\n",A.x,A.y,B.x,B.y);
if (!B.x&&!B.y) return A; return gcd(B,A%B);
}
signed main()
{
RI i; for (scanf("%lld",&n),i=1;i<=n;++i) scanf("%lld%lld",&a[i].x,&a[i].y);
for (i=2;i<=n;++i) a[i]=a[i]-a[1]; for (g=a[2],i=3;i<=n;++i) g=gcd(g,a[i]);
for (i=2;i<=n;++i) a[i]=a[i]/g,mix=min(mix,a[i].x),mxx=max(mxx,a[i].x),
miy=min(miy,a[i].y),mxy=max(mxy,a[i].y); return printf("%lld",max(mxx-mix,mxy-miy)),0;
}