QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546069#6728. To the ParkXiaoretaWWA 55ms4748kbC++202.3kb2024-09-03 19:26:202024-09-03 19:26:25

Judging History

你现在查看的是最新测评结果

  • [2024-09-03 19:26:25]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:4748kb
  • [2024-09-03 19:26:20]
  • 提交

answer

#include <bits/stdc++.h>

#define debug(...) 42;
#ifdef LOCAL
#include "debug.h"
#endif

using namespace std;
#define V vector
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define F(i, l, r) for (int i = l; i < r; ++i)
#define R(i, l, r) for (int i = r-1; i >= l; --i)
typedef long long LL;
typedef double DB;
typedef pair<int, int> PII;
template<typename T> bool setmin(T &a, T b) { return (a > b ? a = b, 1 : 0); }
template<typename T> bool setmax(T &a, T b) { return (a < b ? a = b, 1 : 0); }
// mt19937_64 rng {chrono::steady_clock::now().time_since_epoch().count()};

namespace Primes {
const int N = 100010;
vector<int> primes;
bool st[N];
void init(int n) {
    for (int i = 2; i <= n; i ++ ) {
        if (!st[i]) primes.push_back(i);
        for (int j = 0; primes[j] <= n / i; j ++ ) {
            st[primes[j] * i] = true;
            if (i % primes[j] == 0) break;
        }
    }
}
}
/* -------------Main code------------- */
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    Primes::init(100001);
    reverse(all(Primes::primes));
    int tt; cin >> tt;
    while (tt--) {
        int n; cin >> n;
        vector<int> vis(n + 1);
        vector<pair<int, int>> ans;

        vector<int> even;
        for (int p : Primes::primes) {
            if (p * 2 > n) continue;
            vector<int> cur;
            for (int j = 1; j * p <= n; j++) {
                if (!vis[j * p]) {
                    cur.push_back(j * p);
                    vis[j * p] = 1;
                }
            }
            if ((int) cur.size() % 2 == 1) {
                assert((int) cur.size() >= 3);
                even.push_back(cur[1]);
                cur.erase(cur.begin() + 1);
            }
            for (int i = 0; i < (int) cur.size(); i += 2) {
                ans.push_back({cur[i], cur[i + 1]});
            }
        }

        for (int i = 0; i < (int) even.size(); i++) {
            ans.push_back({even[i], even[i + 1]});
        }

        cout << (int) ans.size() << " \n"[(int) ans.size() == 0];
        for (int i = 0; i < (int) ans.size(); i++) {
            cout << ans[i].fi << ' ' << ans[i].se << " \n"[i == (int) ans.size() - 1];
        }
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3800kb

input:

3
1
4
6

output:

0
1 2 4
2 3 6 2 4

result:

ok 4 cases

Test #2:

score: -100
Wrong Answer
time: 55ms
memory: 4748kb

input:

1007
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101...

output:

0
0
0
1 2 4
1 2 4
2 3 6 2 4
2 3 6 2 4
3 3 6 2 8 4 0
4 3 9 2 8 6 4 4 0
5 5 10 3 9 2 8 6 4 4 0
5 5 10 3 9 2 8 6 4 4 0
5 5 10 3 6 9 12 2 8 4 21963
5 5 10 3 6 9 12 2 8 4 21963
6 7 14 5 10 3 6 9 12 2 8 4 21963
7 7 14 5 15 3 6 9 12 2 8 10 4 4 0
7 7 14 5 15 3 6 9 12 2 4 8 16 10 21963
7 7 14 5 15 3 6 9 12 2...

result:

wrong answer Integer 0 violates the range [1, 8]