91 T了#10
查看原帖
91 T了#10
858275
youshuohan楼主2023/6/3 10:28
#include <bits/stdc++.h>
using namespace std;
bool prime(int x)
{
	if(x<2) return 0;
	for(int i=2;i<=sqrt(x);i++) if(x%i==0) return 0;
	return 1;
}
int pri[35543],cnt;
map<int,bool>h;
bool check(int x)
{
	if(x<2) return 0;
	for(int i=1;i<=cnt;i++)
	{
		if(pri[i]*pri[i]>x) break;
		if(x%pri[i]==0) return 0;
	}
	return 1;
}
void preprime(int x)
{
	for(int i=2;i<=sqrt(x);i++) if(prime(i)) pri[++cnt]=i;
}
int n,m,ans;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	preprime(m);
	for(int i=n;i<=m;i++) if(check(i)) ans++;
	cout<<ans;
	return 0;
}

2023/6/3 10:28
加载中...