![]() |
#2
Jonny02012018-04-15 22:12
|
Input
第一行一个整数n
接下来n行,每行两个数a和b,表示开区间[a,b]
Output
N行,每行输出一个数,表示区间素数的个数
Sample Input
2
2 10
1 100
Sample Output
4
25
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
bool prime(int n,int a,int b)
{
for(int z=a; z<=b; z++)
{
for(int y=a; y<=sqrt(b); y++)
if(z%y==0)
return false;
return true;
}
}
int main()
{
int n,i,j,s=0,z,y;
int a,b;
scanf("%d",&n);
for(int m=1; m<=n; m++)
{
cin>>a>>b;
for(i=a; i<=b; i++)
if(prime(i))
s++;
printf("%d",s);
}
return 0;
}
