【杂文】5亿大质数表(5e8)
在写哈希,刷数论题时曾一度想要查质数,(F**k) 百度文库数据又少,翻页蛋疼,还不给复制,真的是服了。
于是在我闲的蛋疼的时候就搞了个质数表出来。。。。
话不多说,先上代码。
........
噢,不,我还有要说的话。
为了加速,搞了一大堆头文件优化,代码采用的是线筛,共花了 (78.226) (s) ,比我想象的要慢些。
表格刷了 (5) 亿以内的所有质数,再往上就因内存过大而报错了,没办法,只有这么多了。。
输出来的 (txt) 文本文件刚好 (250Mb) ,好衰啊T_T。。。。
(updata(2019.12.15):) 突然意识到没用快读,怪不得这么慢QAQ(改进后只花了 (26.166) (s))。
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC target("avx")
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<cstdio>
#include<ctime>
#define Re register int
const int N=5e8;
int cnt,pri[N/3];bool pan[N+1];
inline void get_pri(){
for(Re i=2;i<=N;++i){
if(!pan[i])pri[++cnt]=i;
for(Re j=1;j<=cnt&&i*pri[j]<=N;++j){
pan[i*pri[j]]=1;
if(i%pri[j]==0)break;
}
}
}
inline void print(Re x){if(x>9)print(x/10);putchar('0'+x-x/10*10);}
int main(){
freopen("5e8大质数表(5亿).txt","w",stdout);
get_pri();
for(Re j=0,i=1;i<=cnt;++i){
if(j++>8)puts(""),j=0;
print(pri[i]),putchar(' ');
}
printf("
Time: %lf s
",(double)clock()/(double)CLOCKS_PER_SEC);
}