0分,RE求调
查看原帖
0分,RE求调
1494926
wuchengjun05楼主2024/10/25 19:49

(思想:欧拉筛预处理)

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int x,m,T,i,j,cnt,pri[N+1],e[N+1],f[N+1],lo;
signed main(){
    memset(e,0x3f,sizeof(e));
    cin>>m>>T;
    for(i=2;i<=N;i++){
        if(!f[i]){
            pri[++cnt]=i;
            for(j=i*i;j<=N;j+=i*i) if(j>=m)e[j]=0;
        }
        for(j=1;j<=cnt&&i*pri[j]<=N;j++){
            f[i*pri[j]]=1;
            if(i%pri[j]==0) break;
        }
    }
    for(i=N;i>=1;i--){
        lo++;
        if(e[i]==0) lo=0;
        e[i]=lo;
    }
    while(T--){
        cin>>x;
        if(e[x]) cout<<e[x]<<endl;
        else cout<<"lucky\n";
    }
}
2024/10/25 19:49
加载中...