CSU 1803

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liufengwei1/article/details/82191089

签到题,然而我不会做,天啊,最后队友秒掉了,我还是不会做

赛后看了一哈,因为x*y%2016=0 等价于 x%2016*y%2016=0

那么我们把1-n中间取模后为i的数字有多少个定位cntx[i],1-m中间取模的数字为cnty[i]

那枚举x的余数和y的余数,乘起来是否为2016的倍数就行了

和湘潭那题不同,这题2016=2^5*3^2*7,按质因子考虑容斥很复杂= =

#include<cstdio>
#include<cstring>
#define maxl 3000

long long n,m,a,b,c,d,ans;
int cntx[maxl],cnty[maxl];

inline void prework()
{
	long long low,up;
	cntx[0]=n/2016;
	cnty[0]=m/2016;
	for(int i=1;i<2016;i++)
	{
		cntx[i]=n/2016;
		cnty[i]=m/2016;
	}
	for(int i=n/2016*2016+1;i<=n;i++)
		cntx[i%2016]++;
	for(int i=m/2016*2016+1;i<=m;i++)
		cnty[i%2016]++;
}

inline void mainwork()
{
	ans=0;
	for(int i=0;i<2016;i++)
		for(int j=0;j<2016;j++)
		if(i*j%2016==0)
		{
			ans+=1ll*cntx[i]*cnty[j];
		}
}

inline void print()
{
	printf("%lld\n",ans);
}

int main()
{
	while(~scanf("%lld%lld",&n,&m))
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/liufengwei1/article/details/82191089
今日推荐