aaa 100000以内的质数表 最近在PKU上面做题,发现好多题目都用到了质数表,于是干脆把100000以内的质数表和生成质数的程序贴上来好了,大家也好抄,直接用~~~ 嘿嘿…… Program: #include #define N 100000 int sieve[N + 1]; void main() { for(int i = 2; i <= N; i++) sieve[i] = 1; for(i = 2; i <= N / 2; i++) sieve[i * 2] = 0; int p = 2; while(p * p <= N) { p = p + 1; while(sieve[p] == 0) p++; int t = p * p; int s = 2 * p; while(t <= N) { sieve[t] = 0; t = t + s; } } ofstream outfile("s.txt",ios::out); for(i = 2; i <= N; i++) if(sieve[i] != 0) outfile<