-
Notifications
You must be signed in to change notification settings - Fork 0
/
11502_math.cpp
53 lines (52 loc) · 992 Bytes
/
11502_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
// 210123 #11502 ¼¼ °³ÀÇ ¼Ò¼ö ¹®Á¦ Silver III
// Bruth-force, Math(eratosthenes' sieve)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1001;
bool prime[MAX];
vector<int> v;
void sieve() {
fill(prime, prime + MAX, true);
for (int i = 2; i * i < 1000; i++) {
if (!prime[i])
continue;
for (int j = i * 2; j < 1000; j += i) {
prime[j] = false;
}
}
}
// if this code in main,
// break; break; break; -> longer code
void find(int num) {
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.size(); j++) {
for (int k = 0; k < v.size(); k++) {
if (v[i] + v[j] + v[k] == num) {
cout << v[i] << " " << v[j] << " " << v[k] << "\n";
return;
}
}
}
}
cout << 0 << "\n";
return;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
sieve();
for (int i = 2; i < 1000; i++) {
if (prime[i])
v.push_back(i);
}
while (t--) {
int N;
cin >> N;
find(N);
}
}