关于素数的具体问题
這個純屬個人好玩所寫
? ? ? ? ? ? ? ? ? ? ? ? ? 上次看到有大神說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
總結
- 上一篇: JAVA 数组元素的反转
- 下一篇: 677A