社区讨论
46分,MLE求助!
P1835素数密度参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @ly761oen
- 此快照首次捕获于
- 2024/07/04 19:11 2 年前
- 此快照最后确认于
- 2024/07/04 21:19 2 年前
CPP
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z,o) for(int o=x;o<=y;o+=z)
const int N=8000005;
using namespace std;
LL prime[N];
bool f[N];
void read(LL &sum)
{
sum=0;int p=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') p=-1;
for(; isdigit(ch);ch=getchar()) sum=sum*10+ch-48;
sum*=p;
}
void write(LL x)
{
if(x>9)
{
write(x/10);
x%=10;
}
putchar(x+'0');
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
LL cnt=0,ans=0;
LL a,b;
read(a);
read(b);
f[1]=1;
F(2,b,1,i)
{
if(f[i]==0) prime[cnt++]=i;
for(int j=0;prime[j]<=b/i;j++)
{
f[prime[j]*i]=1;
if(i%prime[j]==0) break;
}
}
F(a,b,1,i)
{
if(!f[i]) ans++;
}
write(ans);
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...