Preprocessing prime:

1 void init() 2 { 3 memset(Is_or,0,sizeof(Is_or)); 4 for(int j=2; j<sqrt(maxn); J++) {/ / 5 6 the if (Is_or [j] = = 0) / / remove the sum Numbers of multiple. 7 for (int k = j + j; k<=maxn; K +=j)// remove multiples (mark all multiples of composite numbers as not prime) 8 Is_or[k]=1; 9 } 10 for(int i=2; i<=maxn; i++) 11 { 12 if(Is_or[i]==0) 13 { 14 su[cont++]=i; 15} 16} 17}Copy the code