46分,MLE求助!
查看原帖
46分,MLE求助!
987407
luolie0804楼主2024/7/4 19:09
#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;
}

2024/7/4 19:09
加载中...