版权声明:转载无所谓的。。。 https://blog.csdn.net/xuxiayang/article/details/82501830
链接
https://www.luogu.org/problemnew/show/P2429
大意
给定 个质数,求所有含有这些质因数且小于 的并集并求和,输出该和
思路
首先转换一下题目。。。
含有这些质因数的数其实就是这些数的倍数,并集即为不重复出现,于是该题便转化成了
求出一组数的倍数小于m的数去重后的总和
由于数据很水,暴力模拟再加上 或者 判重即可
代码
#include<cstdio>
#include<map>
using namespace std;int n,m,a,ans;
const int ymw=376544743;
map<int,bool>cx;
signed main()
{
scanf("%d%d",&n,&m);
for(register int i=1;i<=n;i++)
{
scanf("%d",&a);
for(register int j=a;j<=m;j+=a)
{
if(cx.find(j)==cx.end()) ans+=j%ymw,ans%=ymw;//hash判断该数是否出现过
cx[j]=1;//标记
}
}
printf("%d",ans);
}