poj: 2262

简单题

 1 #include <iostream>

 2 #include <stdio.h>

 3 #include <string>

 4 #include <stack>

 5 #include <map>

 6 #include <vector>

 7 #include <algorithm>

 8 using namespace std;

 9 

10 bool isPrime(int n) {

11     if (n == 2) return true;

12     if (n % 2 == 0 || n == 1) return false;

13     for (int i = 3; i*i <= n; ++i) {

14         if (n % i == 0) return false;

15     }

16     return true;

17 }

18 

19 int main()

20 {

21     int N;

22     while (cin >> N && N) {

23         bool flag = false;

24         for (int i = 3; i <= N/2; i+=2) {

25             if (isPrime(i) && isPrime(N-i)) {

26                 flag = true;

27                 cout << N << " = " << i << " + " << N-i << endl;

28                 break;

29             }

30         }

31         if (!flag) cout << "Goldbach's conjecture is wrong." << endl;

32     }

33 

34     return 0;

35 }

 

你可能感兴趣的:(poj)