Pages

Friday, July 29, 2011

a121. 質數又來囉


#include
using namespace std;
#include

int main()
{
int a,b;
while(cin>>a>>b)
{
int prime_num=0;
for(int num=a;num<=b;num++)
{
if (num==1) continue;
else if(num==2){ prime_num++;continue;}
else if(num==3) { prime_num++;continue;}
else
{
int flag_isprime=1;
for(int factor=2;factor<=sqrt(num)+1;factor++)
if(num%factor==0){flag_isprime=0;break;}
if (flag_isprime==1)
prime_num++;
}
}
cout< }
return 0;
}

No comments:

Post a Comment