1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 int main(){ 6 int n=100,t; 7 bool a[105]; 8 for(int i=0;i<=n;i++){ 9 a[i]=true; 10 } 11 a[1]=false; 12 for(int i=2;i<=sqrt(n);i++){ 13 if(a[i]){ 14 for(int j=2;j<=n/i;j++){ 15 a[i*j]=false; 16 } 17 } 18 } 19 t=0; 20 for(int i=2;i<=n;i++){ 21 if(a[i]){ 22 printf("%5d",i); 23 t++; 24 if(t%5==0){ 25 printf("\n"); 26 } 27 } 28 } 29 return 0; 30 }
原文:https://www.cnblogs.com/bjt1015/p/11991594.html