Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!
Input The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.
peter 想要收集一些素数从他的密码体系中,帮帮他,你的任务就是去收集所有的素数从两个给定的
数字之间。
input 开始输入的数字t是测试样例的数量在第一行,在下面的t行的每一行都有两个数字m和n,m,
n中间有一个空格。
output 每一个测试样例输出所有在m,n之间所有的素数,一个数字一行,每个测试样例之间用一个
空行来区分
#include<iostream>
using namespace std;
bool puanduan(int x)
{
if (x < 2) return 0;
for (int i = 2; i <= x/i; i++)
{
if (x%i==0)
{
return 0;
}
}
return 1;
}
int main()
{
int n;
cin >> n;
while (n--)
{
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++)
{
if (puanduan(i))
{
cout << i << endl;
}
}
cout << endl;
}
}