P3383 【模板】线性筛素数
用solve函数完成线性筛,但在最后输出答案时
用for会T3个点,而用while就能A??
而且感觉用ios::sync_with_stdio(false);优化过后,
cin,cout比scanf,printf要慢?
萌新迷惑QWQ(下面是代码
#include<bits/stdc++.h>
#define M 100000100
using namespace std;
bool zs[M];
int tot,pri[M/10];
void solve(int n)
{
for(int i=2;i<=n;++i)
{
if(!zs[i]) pri[++tot]=i;
for(int j=1;j<=tot && i*pri[j]<=n;++j)
{
zs[ i*pri[j] ]=true;
if( i% pri[j] ==0 )break;
}
}
}
int main()
{
ios::sync_with_stdio(false);
int n,m;cin>>n;
solve(n);
cin>>m;
while(m--)//原本写的是for(int i=1;i<=m;++i),T了3个点
{
int a;cin>>a;
cout<<pri[a]<<endl;
}
}
)