为什么RE啊,求大佬帮助

P3383 【模板】线性筛素数

yingxiaofei @ 2024-12-25 00:40:53

#include<stdio.h>
#include<string.h>
int Prime[100000001];
int isPrime[100000001];
int sum=0;
void get_Prime(int n)
{
    isPrime[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!isPrime[i])
        {
            Prime[++sum]=i;
        }
        for(int j=1;j<=sum&&i*Prime[j]<=n;j++)
        {
            isPrime[i*Prime[j]]=0;
            if(i%Prime[j]==0)
            {
                break;
            }
        }
    }
}  
int main()
{
    int n,q,find;
    scanf("%d %d",&n,&q);
    get_Prime(n);
   for(int i=1;i<=q;i++)
      {
        scanf("%d",&find);
        printf("%d\n",Prime[find]);
      }
    return 0;
 } 

by guoxinchen @ 2024-12-25 07:59:21

@yingxiaofei isPrime[i*Prime[j]]=0;写错了,应该赋值为1


by yingxiaofei @ 2024-12-25 21:45:07

@guoxinchen谢谢dalao


|