Hankson 的趣味题

时间:2021-11-25 04:53:27

题解:

硬是把一道傻逼题写到了200行。。

长长的模板就有70行。。

由于我没有做的时候觉得并不保证$a1|a0$ $b0|b1$ 然后就加了很多特判。。

我的做法就是暴力分解质因数

T*sqrt(n)/log(n)

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define rg register
#define IL inline
#define ll long long
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
#define setit set<int>::iterator
#define fi first
#define se second
#define mp make_pair
#define me(x) memset(x,0,sizeof(x))
#define mid ((h+t)>>1)
#define mid2 ((h+t+1)>>1)
char ss[<<],*A=ss,*B=ss;
IL char gc()
{
return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;
}
template<class T>void read(T &x)
{
rint f=,c; while (c=gc(),c<||c>) if (c=='-') f=-; x=(c^);
while (c=gc(),c>&&c<) x=(x<<)+(x<<)+(c^); x*=f;
}
char sr[<<],z[]; int Z,C=-;
template<class T>void wer(T x)
{
if (x<) sr[++C]='-',x=-x;
while (z[++Z]=x%+,x/=);
while (sr[++C]=z[Z],--Z);
}
IL void wer1()
{
sr[++C]=' ';
}
IL void wer2()
{
sr[++C]='\n';
}
template<class T>IL void maxa(T &x,T y)
{
if (x<y) x=y;
}
template<class T>IL void mina(T &x,T y)
{
if (x>y) x=y;
}
template<class T>IL T MAX(T x,T y)
{
return x>y?x:y;
}
template<class T>IL T MIN(T x,T y)
{
return x<y?x:y;
}
const int N=5e4;
const int M=N+1e3;
int f[M],cnt,g1[M],g2[M],g3[N],g4[N];
bool t[M],tt;
IL int fj(int *a,int b)
{
rep(i,,cnt)
while (b%f[i]==) a[i]++,b/=f[i];
return b;
}
IL void prf()
{
wer(); wer2();
tt=;
}
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
rep(i,,N)
if (!t[i])
{
for (int j=;j*i<=N;j++) t[i*j]=;
}
rep(i,,N) if (!t[i]) f[++cnt]=i;
int n,a0,a1,b0,b1;
read(n);
rep(i,,n)
{
read(a0); read(a1); read(b0); read(b1);
rep(j,,cnt) g1[j]=g2[j]=g3[j]=g4[j]=;
int t1,t2,t3,t4;
t1=fj(g1,a0); t2=fj(g2,a1);
t3=fj(g3,b0); t4=fj(g4,b1);
ll ans=;
tt=;
rep(i,,cnt)
{
if (g1[i]<g2[i]||g3[i]>g4[i])
{
prf(); break;
}
if (g1[i]>g2[i])
{
if (g3[i]<g4[i])
if (g4[i]!=g2[i])
{
prf(); break;
}
if (g3[i]==g4[i])
{
if (g3[i]<g2[i])
{
prf(); break;
}
}
} else
{
if (g3[i]<g4[i])
if (g4[i]<g2[i])
{
prf(); break;
}
if (g3[i]==g4[i])
{
if (g3[i]<g2[i])
{
prf(); break;
} else
{
ans*=(g3[i]-g2[i]+);
}
}
}
}
if (tt) continue;
if (t2!=)
{
if (t1!=t2)
{
prf();
} else
{
if ((t3!=&&t3!=t2)||(t4!=t2)) prf();
else wer(ans),wer2();
}
} else
{
if (t1==)
{
if (t4==&&t3==)
{
wer(ans); wer2();
} else
if (t4==&&t3!=)
{
prf();
} else
if (t4!=&&t3==)
{
wer(ans); wer2();
} else
{
if (t4==t3) wer(ans*),wer2();
else prf();
}
} else
{
if (t4==&&t3==)
{
wer(ans); wer2();
} else
if (t4==&&t3!=)
{
prf();
} else
if (t4!=&&t3==)
{
if (t1!=t4) wer(ans),wer2();
else prf();
} else
{
if (t3==t4)
if (t3!=t1) wer(ans*),wer2();
else wer(ans),wer2();
else prf();
}
}
}
}
fwrite(sr,,C+,stdout);
return ;
}