-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime_1322.cpp
More file actions
52 lines (46 loc) · 974 Bytes
/
Copy pathprime_1322.cpp
File metadata and controls
52 lines (46 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* 1322: 欧拉版哥德巴赫猜想
* http://oj.ryipedu.com/problem.php?id=1322
*
* 任一大于2的偶数都可写成两个素数之和.
*/
#include <iostream>
#include <math.h>
using namespace std;
bool is_prime(int x)
{
int val = sqrt(x);
for (int i = 2; i <= val; i++)
if (!(x % i))
return false;
return true;
}
int main()
{
int n, a[1000], ai = 0;
cin >> n;
// find all prime less than n
for (int i = 2; i < n; i++)
{
if (is_prime(i))
{
a[ai++] = i;
}
}
for (int i = 0; i < ai; i++)
{
for (int j = 0; j < ai; j++)
{
if(a[i] + a[j] == n)
{
if(a[i] <= a[j]) {
cout << a[i] << " " << a[j] << endl;
} else {
cout << a[j] << " " << a[i] << endl;
}
return 0;
}
}
}
return 0;
}