codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)

题目链接:http://www.codeforces.com/problemset/problem/472/A
题意:给你一个数n,将n表示为两个合数(即非素数)的和。
C++代码:

#include <iostream>
using namespace std;
bool isprime(int x)
{
    for (int i = 2; i * i <= x; i ++)
        if (x % i == 0)
            return false;
    return true;
}
int main()
{
    int n;
    cin >> n;
    for (int i = 4;i <= n/2; i ++)
        if (!isprime(i) && !isprime(n-i)) {
            cout << i << " " << n-i << endl;
            break;
        }
    return 0;
}
C++

 

posted @ 2016-07-20 16:33  月光诗人  阅读(323)  评论(0编辑  收藏  举报