跳到正文

题解

题解 P2429 【制杖题】

syf2008约 1 分钟
原文
文章信息与版本

文章信息

发布
2020年9月12日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
题目
P2429

版本

  1. v2当前
  2. v1

这不就是线筛吗(map版)

C++
#include <bits/stdc++.h>
using namespace std;
int n,m,s;
long long sum=0;
map<int,bool>a;//注意,第二个变量要用bool(因为只有0和1),不然会MLE(我也不知道会不会,但能省就省)
int main()
{
	scanf("%d%d",&n,&m);
	while(n--)
	{scanf("%d",&s);
	for(int j=s;j<=m;j+=s)//把它的倍数标记
	if(!a[j])
	{sum+=j;//累计和
	a[j]=1;}}
	printf("%lld",sum%376544743);//取模很重要
}
原文
存档评论1 条抓取于