5. 素数对
题目ID:6367必做题100分
最新提交:
Time Limit Exceeded
40 分
历史最高:
Time Limit Exceeded
40 分
时间限制: 1000ms
空间限制: 524288kB
题目描述
两个相差为2的素数称为素数对,如5和7,17和19等,本题目要求找出所有两个数均不大于n的素数对。
输入格式
一个正整数n。
输出格式
所有小于等于n的素数对。每对素数对输出一行,中间用单个空格隔开。若没有找到任何素数对,输出empty。
样例
Input 1
100
Output 1
3 5 5 7 11 13 17 19 29 31 41 43 59 61 71 73
Input 2
2
Output 2
empty
样例解释
输入100时,小于等于100的素数对有8对,所以输出8行;输入2时,没有小于等于2的素数对,所以输出empty。
数据范围
1≤n≤10000
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,s=0;
cin>>n;
for(int i=3;i<n;i+=2)
{
s+=i;
for(int a=2;a<s;a++)
{
if(s%a==0)
{
continue;
}
else
{
if((s+2)%a==0)
{
cout<<s<<" "<<s+2<<endl;
}
else
{
continue;
}
}
}
}
if(n<=4)
{
cout<<“empty”;
}
return 0;
}