64,653
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
int n=10000;
int a[10000];
for(int a1=0;a1 <n;a1++)
a[a1]=0;
a[0]=2;
a[1]=3;
int k=1;
int tmp=0;
for(int i=4;i <=n;i++)
{
tmp=(int)sqrt(i);
for(int j=1;j <=tmp;)
{
j++;
if(i%j==0)
break;
else
{
if(j>tmp)
{
++k;
a[k]=i;
}
}
}
}
for(int m=0;m <1000;m++)
{
if(m%5==0) //5 items per line
cout <<endl;
cout <<setw(5) <<a[m];
}
cout <<endl;
return 0;
}
//不好意思,错了一点点,上面的。
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
int n=10000;
int a[10000];
for(int a1=0;a1 <n;a1++)
a[a1]=0;
a[0]=2;
a[1]=3;
int k=1;
int tmp=0;
for(int i=4;i <=n;i++)
{
tmp=(int)sqrt(i);
for(int j=2;j <tmp;j++)
{
if(i%j==0)
break;
else
{
if(i>j)
{
++k;
a[k]=i;
}
}
}
}
for(int m=0;m <1000;m++)
{
if(m%5==0) //5 items per line
cout <<endl;
cout <<setw(5) <<a[m];
}
cout <<endl;
return 0;
}
//楼主真是害人,要不是我心情不好我才不帮你看了。
//
for(int j=2;j <=(int)sqrt(i);j++)
{
if(i%j==0)
break;
else if(i>j)
a[k]=i;
}