比赛 20160303 评测结果 AAAAAAAAAA
题目名称 Hankson的趣味题 最终得分 100
用户昵称 mikumikumi 运行时间 0.113 s
代码语言 C++ 内存使用 0.38 MiB
提交时间 2016-03-03 19:08:54
显示代码纯文本
#include<cstdio>
#include<deque>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long LL;
const int SIZEN=2010,SIZEP=50000;
int N;
LL a1[SIZEN],a0[SIZEN],b1[SIZEN],b0[SIZEN];
LL ma=0;
deque<LL> P;
void read()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%lld%lld%lld%lld",&a0[i],&a1[i],&b0[i],&b1[i]);
		ma=max(b1[i],ma);
	}
}
void Prime(LL n)
{
	LL m=min(n,(LL)SIZEP);
	bool inq[SIZEP+10]={0};
	for(LL i=2;i<=m;i++)
	{
		if(!inq[i])
		{
			P.push_back(i);
			for(LL j=i*i;j<=m;j+=i) inq[j]=1;
		}
		//cout<<i<<endl;
	}
}
LL kon(LL &a,LL p)
{
	LL ans=0;
	while(a%p==0)
	{
		a/=p;
		ans++;
	}
	return ans;
}
LL deal(int x)
{
	LL ans=1;
	LL na=a0[x],ta=a1[x],nb=b0[x],tb=b1[x];
	for(int i=0;i<P.size();i++)
	{
		if(P[i]*P[i]>tb) break;
		LL low=0,high=0;
		LL p1=kon(na,P[i]),p2=kon(ta,P[i]),p3=kon(nb,P[i]),p4=kon(tb,P[i]);
		low=p2;
		if(p3<p4) low=p4;
		high=p4;
		if(p1>p2) high=p2;
		if(high>=low) ans*=(high-low+1);
		else ans=0;
		//if(x==1) cout<<P[i]<<" "<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;
	}
	if(tb>1)
	{
		LL low=0,high=0;
		LL p1=kon(na,tb),p2=kon(ta,tb),p3=kon(nb,tb),p4=kon(tb,tb);
		low=p2;
		if(p3<p4) low=p4;
		high=p4;
		if(p1>p2) high=p2;
		if(high>=low) ans*=(high-low+1);
		else ans=0;
	}
	return ans;
}
int main()
{
	freopen("son.in","r",stdin);
	freopen("son.out","w",stdout);
	read();
	Prime(ma);
	for(int i=1;i<=N;i++) printf("%lld\n",deal(i));
	return 0;
}