[C#] 纯文本查看 复制代码 public static int[] PrimeList;
public static void FindPrime(int n)
{
int[] IntList;
int len=n-1;
IntList=new int[n];
for (int p=2;p<=n;p++) IntList[p-1]=p;
for (int p=2;p<Math.Sqrt(n);p++)
{
if (IntList[p-1]==0) continue;
int j=p*p;
while (j<=n)
{
if (IntList[j-1]!=0 )
{
IntList[j-1]=0;
len=len-1;
}
j=j+p;
}
}
PrimeList=new int[len];
int i=0;
for (int p=2;p<=n;p++)
{
if (IntList[p-1]!=0)
{
PrimeList[i]=IntList[p-1];
i=i+1;
}
}
} |