请问这种写法时间复杂度是线性的吗?
查看原帖
请问这种写法时间复杂度是线性的吗?
989997
DGL__DGL_AFO楼主2024/1/15 22:35

rt

#include<bits/stdc++.h>
using namespace std;
int ans;
bool st[1145141919];
int n,m,a,b;
int main()
{
	cin>>n>>m;
	a=max(m,n);
	b=min(n,m);
	n=b;m=a;
	st[1]=1;
	for(int i=2;i<=m;i++)
		if(st[i]==0)
		  for(int j=2;j*i<=m;j++)
		    st[i*j]=1;
	for(int i=n;i<=m;i++)	
		if(st[i]==0)  
		  ans++;
		
	
	cout<<ans;
	
	
	return 0;
}
2024/1/15 22:35
加载中...