开区间[L, R]中的整数L,R

  • Post author:
  • Post category:其他



#include <iostream>

#include<cmath>

using namespace std;


int main()

{

int a,b;

int x,i,count=0;

cin>>a>>b;

if(a!=0&&a!=1){

for(x=a;x<=b;x++)



{



for(i=2;i<=sqrt(x);i++)



{if(x%i==0) break;}



if(i>sqrt(x)) count++;}}

else if(a==0){

count=-2;

for(x=a;x<=b;x++)



{



for(i=2;i<=sqrt(x);i++)



{if(x%i==0) break;}



if(i>sqrt(x)) count++;}


}

else if(a==1){

count=-1;

for(x=a;x<=b;x++)



{



for(i=2;i<=sqrt(x);i++)



{if(x%i==0) break;}



if(i>sqrt(x)) count++;}


}

cout<<count<<endl;

return 0;

}




版权声明:本文为huzi99原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。