栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ZZULIOJ 2809: OH哥的倍数问题(Hard Version)(容斥定理)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ZZULIOJ 2809: OH哥的倍数问题(Hard Version)(容斥定理)

2809: OH哥的倍数问题(Hard Version)

#include
typedef long long LL;
int n;
LL get(int x){return 1LL*(1+n/x)*(n/x)*x/2;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b,int c,int d,int e)
{
	int x=a*b/gcd(a,b);
	x=x*c/gcd(x,c);
	x=x*d/gcd(x,d);
	x=x*e/gcd(x,e);
	return x;
}
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		int a,b,c,d,e;scanf("%d%d%d%d%d%d",&n,&a,&b,&c,&d,&e);
		LL res=get(a)+get(b)+get(c)+get(d)+get(e);
		res=res-get(lcm(a,b,1,1,1))
			   -get(lcm(a,c,1,1,1))
			   -get(lcm(a,d,1,1,1))
			   -get(lcm(a,e,1,1,1))
			   -get(lcm(b,c,1,1,1))
			   -get(lcm(b,d,1,1,1))
			   -get(lcm(b,e,1,1,1))
			   -get(lcm(c,d,1,1,1))
			   -get(lcm(c,e,1,1,1))
			   -get(lcm(d,e,1,1,1));
		res=res+get(lcm(a,b,c,1,1))
			   +get(lcm(a,b,d,1,1))
			   +get(lcm(a,b,e,1,1))
			   +get(lcm(a,c,d,1,1))
			   +get(lcm(a,c,e,1,1))
			   +get(lcm(a,d,e,1,1))
			   +get(lcm(b,c,d,1,1))
			   +get(lcm(b,c,e,1,1))
			   +get(lcm(b,d,e,1,1))
			   +get(lcm(c,d,e,1,1));
		res=res-get(lcm(a,b,c,d,1))
			   -get(lcm(a,b,c,e,1))
			   -get(lcm(a,b,d,e,1))
			   -get(lcm(a,c,d,e,1))
			   -get(lcm(b,c,d,e,1));
		res=res+get(lcm(a,b,c,d,e));
		printf("%lldn",res);
	}
	return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/698347.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号