#include<iostream>
using namespace std;
int main()
{
int num1, num2;
do
{
char a;//判断是否再次输入
cout << "请输入范围" << endl;
cin >> num1 >> num2;
int c = num1 - num2;//判断范围是否大于10000
int i = min(num1, num2), m = max(num1, num2);//计算是否为素数
int count = 0;//记录质数数目
int flag=0;//多次判断是否再次进行时,用于跳出循环
if (c > 10000 || c < -10000)
{
cout << "可能会花费较长计算时间,请重新输入" << endl;
cout << "重新输入请键入“Y”,不重新输入请键入“N”,输入其他无效" << endl;
cin >> a;
if (a == 'Y')
{
continue;
}
else if (a == 'N');
else while (1)
{
cout << "输入无效,请重新输入" << endl;
cout << "重新输入请键入“Y”,不重新输入请键入“N”,输入其他无效" << endl;//再次提醒是否输入
cin >> a;
if (a == 'Y')
{
flag = 1;
break;
}
if (a == 'N')
{
break;
}
else
continue;
}
if (flag == 1)
continue;
}
if (num1 == num2)
{
cout << "两数相同,请重新输入。" << endl;
continue;
}
for (i; i < 2*m; i++)
{
if (i <= 1)
continue;
int z = 0;
for (z = 2; z <=i; z++)
{
if (i % z == 0)
break;
if (z < i - 1)
continue;
cout << i << " ";//间隔为一个空格输出质数
count++;
}
}
cout << endl;//换行
cout << num1 << "和" << num2 << "之间的质数个数为" << count << endl;
} while (1);
return 0;
}