1013 数素数

#include 
#include 
#include 
//int S[1005]={0};     error
int S[105000]={0};
int is_sushu(int n){
    for(int i = 2;i<=sqrt((double)n);i++){
        if(n%i==0) return 0;
    }
    return 1;
}
int main()
{
    //freopen("C:\\Users\\pc\\Desktop\\use.txt","r",stdin);
    int M,N;
    scanf("%d %d",&M,&N);
    int row_num = 1;
    int account = 0;

    //for(int i = 2;i < 1005 && account <= N-1; ++i){  error
    for(int i = 2;i < 105000 && account <= N-1; ++i){
        if(is_sushu(i)) 
            {
                S[account] = i;
            if(account >= M-1){
                if(account == N-1) {printf("%d",i);break;}
            if(row_num <= 9) {printf("%d ",i);row_num++;}
            else if(row_num == 10){printf("%d\n",i);row_num = 1;}
        }
            account++;

        }
        
    }

    return 0;
}
//4答案错误
//百度:需要注意最大N=10000,即第10000个素数大约在105000 内;这也是测试点4所测试的

你可能感兴趣的:(1013 数素数)