生成质数数组
#include <iostream> using namespace std; const int MAXP = 200; bool pm[MAXP+1]; void primes() { memset(pm,1,MAXP); int i,j; for ( i=2; i<=MAXP; i++ ) { if ( pm[i] ) { j = 2*i; while ( j<=MAXP ) { pm[j] = false; j += i; } } } } int main() { primes(); int i; for ( i=2; i<=MAXP; i++ ) { if ( pm[i] ) cout << i << " "; } cout << endl; }