Description
编写函数1,判断一个数是否是素数,
主函数中,找出m~n之间的所有素数
Input
整数m n
Output
所有素数
Sample Input
7 20
Sample Output
7 11 13 17 19
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
using namespace std;
const int maxn=1e6+7;
int prime[maxn];
int main()
{
int m,n,i,j,a,d=1;
scanf("%d %d",&m,&n);
memset(prime,0,sizeof(prime));
prime[0]=1;
prime[1]=1;
a=sqrt(maxn);
for(i=2; i<=a; i++)
{
if(prime[i]==0)
{
for(j=i*i; j<maxn; j+=i)
{
prime[j]=1;
}
}
}
for(i=m; i<=n; i++)
if(prime[i]==0)
{
if(d==0)
{
printf(" %d",i);
}
if(d==1)
{
printf("%d",i);
d=0;
}
}
return 0;
}
478



被折叠的 条评论
为什么被折叠?



