Hankson 的趣味题

题解:

硬是把一道傻逼题写到了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[1<<24],*A=ss,*B=ss;
IL char gc()
{
  return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++;
}
template<class T>void read(T &x)
{
  rint f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48);
  while (c=gc(),c>47&&c<58) x=(x<<3)+(x<<1)+(c^48); x*=f;
}
char sr[1<<24],z[20]; int Z,C=-1;
template<class T>void wer(T x)
{
  if (x<0) sr[++C]='-',x=-x;
  while (z[++Z]=x%10+48,x/=10);
  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,1,cnt)
    while (b%f[i]==0) a[i]++,b/=f[i];
  return b;
}
IL void prf()
{
  wer(0); wer2();
  tt=1;
}
int main()
{
  freopen("1.in","r",stdin);
  freopen("1.out","w",stdout);
  rep(i,2,N)
    if (!t[i])
    {
      for (int j=2;j*i<=N;j++) t[i*j]=1;
    }
  rep(i,2,N) if (!t[i]) f[++cnt]=i;
  int n,a0,a1,b0,b1;
  read(n);
  rep(i,1,n)
  {
    read(a0); read(a1); read(b0); read(b1);
    rep(j,1,cnt) g1[j]=g2[j]=g3[j]=g4[j]=0;
    int t1,t2,t3,t4;
    t1=fj(g1,a0); t2=fj(g2,a1);
    t3=fj(g3,b0); t4=fj(g4,b1);
    ll ans=1;
    tt=0;
    rep(i,1,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]+1);
          }
        }
      }
    }
    if (tt) continue;
    if (t2!=1)
    {
      if (t1!=t2)
      {
        prf();
      } else
      {
        if ((t3!=1&&t3!=t2)||(t4!=t2)) prf();
        else wer(ans),wer2();
      }
    } else
    {
      if (t1==1)
      {
        if (t4==1&&t3==1)
        {
          wer(ans); wer2();
        } else
        if (t4==1&&t3!=1)
        {
          prf();
        } else
        if (t4!=1&&t3==1)
        {
          wer(ans); wer2();
        } else
        {
          if (t4==t3) wer(ans*2),wer2();
          else prf();
        }
      } else
      {
        if (t4==1&&t3==1)
        {
          wer(ans); wer2();
        } else
        if (t4==1&&t3!=1)
        {
          prf();
        } else
        if (t4!=1&&t3==1)
        {
          if (t1!=t4) wer(ans),wer2();
          else prf();
        } else
        {
          if (t3==t4)
            if (t3!=t1) wer(ans*2),wer2();
            else wer(ans),wer2();
          else prf();
        }
      }
    }
  }
  fwrite(sr,1,C+1,stdout);
  return 0;
}

 

posted @ 2018-11-09 09:11  尹吴潇  阅读(173)  评论(0编辑  收藏  举报