输入两个整数X和Y,输出两者之间的素数个数(包括X和Y)。
1 100
25
代码:
/*****************/ //NAME:ChengtaoGuo //DATE:2017-08-02 //SOURCE:BAILIANOJ /****************/ #include<iostream> #include<cmath> using namespace std; int max(int a,int b) {return a>b?a:b;} int min(int a,int b) {return a<b?a:b;} int flag=0; int main() { int i,j,x,y,c,d;int count=0; cin>>x>>y; c=min(x,y); d=max(x,y); for(i=c;i<=d;i++) { flag=0; for(j=2;j<=sqrt(i);j++) { if(i%j==0) { flag=1; break; } } if(flag==0) { count++; } } if(min(x,y)==1) cout<<count-1<<endl; else cout<<count<<endl; return 0; }
原文:http://www.cnblogs.com/gcter/p/7273669.html