Description
这次你的任务是编程序把m和n之间的素数个数(如果n和m本身是素数,那么包括n和m)统计出来。
Input
输入只有一行,两个用空格隔开的正整数n和m,2<=m<=n<=10000。
Output
输出也是一行,m和n之间的素数个数。
Sample Input
20 5
Sample Output
6
简单,上AC代码,(求赞)
include <bits/stdc++.h>
using namespace std;
int main()
{
int a,i,j,b,t=0;
bool k;
cin>>a>>b;
for(i=b;i<=a;i++)
{
k=true;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
k=false;
}
if(k)
t++;
}
cout<<t<<endl;
return 0;
}