关于素数的具体问题

这个纯属个人好玩所写

                          上次看到有大神说1-10^18的素数比较密集,所以TEST了一下

                          先是1—10^7素数最大的距离

                    #include<iostream>

#include<math.h>
#include<algorithm>
using namespace std;
const int maxn=1E7;
int b[maxn],q[maxn],cnt;
int main()
{
  for (int i=2;i*i<=maxn;i++)
      if (b[i]==0)
  {
      q[++cnt]=i;
      for (int j=i+i;j<=maxn;j+=i)
        b[j]=1;
  }
  int ans=0;
  for (int i=1;i<=cnt;i++)
  ans=max(ans,q[i]-q[i-1]);
  cout<<ans<<endl;

} 

 最大距离是:34;

分别是 1327  1361

1-10^8 

最大距离是:36

分别是: 9551 9578

后面的就跑不出来了。。。。

虽然程序简单,但是结论还是非常有用的 

原文地址:https://www.cnblogs.com/forgot93/p/3574859.html