Change the solution to be more simple.
The logic was much more simple than what I could have thought on the contest...
This commit is contained in:
parent
fddaaeba59
commit
88e542c982
@ -74,25 +74,17 @@ int main()
|
|||||||
ios::sync_with_stdio(false);
|
ios::sync_with_stdio(false);
|
||||||
cin.tie(nullptr);
|
cin.tie(nullptr);
|
||||||
|
|
||||||
V<bool> isprime(1e5 * 4 + 1, true);
|
|
||||||
isprime[1] = false;
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= (size_t)1e5 * 4; i++) {
|
|
||||||
if (!isprime[i]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t j = i * 2; j <= (size_t)1e5 * 4; j += i) {
|
|
||||||
isprime[j] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int t;
|
int t;
|
||||||
cin >> t;
|
cin >> t;
|
||||||
while (t--) {
|
while (t--) {
|
||||||
int n;
|
int n;
|
||||||
cin >> n;
|
cin >> n;
|
||||||
|
|
||||||
|
if (n <= 4) {
|
||||||
|
cout << "-1\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
vi odd;
|
vi odd;
|
||||||
vi even;
|
vi even;
|
||||||
|
|
||||||
@ -104,35 +96,16 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = odd.size() - 1;
|
repv(i, odd) {
|
||||||
int j = 0;
|
if (i != 5) {
|
||||||
|
cout << i << ' ';
|
||||||
while (i >= 0) {
|
|
||||||
j = even.size() - 1;
|
|
||||||
while (j >= 0 && isprime[odd[i] + even[j]]) {
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
if (j >= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < 0) {
|
|
||||||
cout << "-1\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t k = 0; k < odd.size(); k++) {
|
|
||||||
if (k != i) {
|
|
||||||
cout << odd[k] << ' ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << odd[i] << ' ' << even[j] << ' ';
|
cout << "5 4 ";
|
||||||
for (size_t k = 0; k < even.size(); k++) {
|
repv(i, even) {
|
||||||
if (k != j) {
|
if (i != 4) {
|
||||||
cout << even[k] << ' ';
|
cout << i << ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << '\n';
|
cout << '\n';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user