标程如下(每行5个,C++程序)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int i,n,j,t=0,k=1,s=1;
cin>>n;
if(n>=2)
cout<<"2"<<" ";
for(i=3;i<=n;i+=2)
{t=0;
if(i%2==0) continue;
for(j=3;j<=sqrt(i);j+=2)
{if(i%j==0) {t=1;break;}}
if(t==0)
{cout<<i<<" ";
k++;s++;}
if(k>=5) {cout<<"\n";
k%=5;}
}
cout<<"\n"<<"the total is:"<<s;
while(1);
}