【[Offer收割]编程练习赛12 A】歌德巴赫猜想

【题目链接】:http://hihocoder.com/problemset/problem/1493

【题意】

【题解】

枚举P从2..n/2
如果P是质数且N-P也是质数;
则输出P和N-P就好;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;

int n;
vector<int> v;

bool is(int x)
{
    int len = sqrt(x);
    rep1(i, 2, len)
        if (x%i == 0)
            return false;
    return true;
}

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    rei(n);
    rep1(i, 2, n / 2)
        if (is(i) && is(n - i))
            return printf("%d %d\n", i, n - i),0;
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:45  AWCXV  阅读(127)  评论(0编辑  收藏  举报