Hankson的趣味题
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const ll maxn=20000+10; ll ma,mb,mc,md,mx,a,b,c,d,x; ll prime[maxn],cnt[maxn]; ll top; bool p[4000000+10]; ll getnum(ll gc,ll t){ ll num=0; while(t%gc==0){ num++; t/=gc; } return num; } ll check(ll gc){ ma=getnum(gc,a); mb=getnum(gc,b); mc=getnum(gc,c); md=getnum(gc,d); ll num=0; if(ma>mc&&mb<md&&mc==md) num++; if(ma>mc&&mb==md&&mc<=md) num++; if(ma==mc&&mb<md&&mc<=md) num++; if(ma==mc&&mb==md&&mc<=md) num+=(md-mc+1); return num; } int main(){ //freopen("vvv.out","w",stdout); ll n; for (ll i=2;i<=2000000;i++){ if(p[i]) continue; for(ll j=i;j<=2000000/i;j++){ p[i*j]=true; } } ll m=0; for (ll i=2;i<=2000000;i++) if(!p[i]) prime[++m]=i; scanf("%lld",&n); while(n--){ top=0; ll ans=1; memset(cnt,1,sizeof(cnt)); scanf("%lld%lld%lld%lld",&a,&c,&b,&d); if (a%c||d%b) {printf("0\n");continue;} for (ll i=1;prime[i]<=d;i++){ if(d%prime[i]==0){ cnt[++top]=check(prime[i]);//prllf("%d\n",cnt[top]); } } for (ll i=1;i<=top;i++){ ans*=cnt[i]; } //if(ans==1) printf("%d\n",0); printf("%lld\n",ans); } return 0; }