forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path472A - Design Tutorial Learn from Math.cpp
71 lines (55 loc) · 1.7 KB
/
472A - Design Tutorial Learn from Math.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer n no less than 12, express it as a sum of two composite numbers.
Input
The only line contains an integer n (12?=?n?=?106).
Output
Output two composite integers x and y (1?<?x,?y?<?n) such that x?+?y?=?n. If there are multiple solutions, you can output any of them.
Examples
inputCopy
12
outputCopy
4 8
inputCopy
15
outputCopy
6 9
inputCopy
23
outputCopy
8 15
inputCopy
1000000
outputCopy
500000 500000
Note
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
*/
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if (n <= 1) return false;
if (n <=3) return true;
if (n % 2== 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int x = 4; x < n; x++) {
if (!isPrime(x)) {
int y = n - x;
if (!isPrime(y)) {
cout << x << " " << y;
break;
}
}
}
return 0;
}