HDU 1262 寻找素数对

来源:互联网 发布:电玩战魂赫卡里姆淘宝 编辑:程序博客网 时间:2024/05/21 05:23

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1262


#include <iostream>#include <cmath>using namespace std;bool is_prime(int n) //素数筛{    for(int i=2; i<=sqrt(n); i++) if(!(n%i)) return 0;    return 1;}int main(){    int n;    while(cin>>n)    {        for(int i=n/2; i>=5; i--) //两个彼此最接近的素数            if(is_prime(i) && is_prime(n-i))            {                cout<<i<<" "<<n-i<<endl;                break;            }    }    return 0;}






0 0
原创粉丝点击