QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546070#6728. To the ParkXiaoretaWAC ✓62ms4556kbC++202.3kb2024-09-03 19:28:402024-09-03 19:28:43

Judging History

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

  • [2024-09-03 19:28:43]
  • 评测
  • 测评结果:AC
  • 用时:62ms
  • 内存:4556kb
  • [2024-09-03 19:28:40]
  • 提交

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 + 1 < (int) cur.size(); i += 2) {
                ans.push_back({cur[i], cur[i + 1]});
            }
        }

        for (int i = 0; i + 1 < (int) even.size(); i += 2) {
            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;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
4
6

output:

0
1 2 4
2 3 6 2 4

result:

ok 4 cases

Test #2:

score: 0
Accepted
time: 62ms
memory: 4556kb

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
2 3 6 2 8
3 3 9 2 8 6 4
4 5 10 3 9 2 8 6 4
4 5 10 3 9 2 8 6 4
4 5 10 3 6 9 12 2 8
4 5 10 3 6 9 12 2 8
5 7 14 5 10 3 6 9 12 2 8
6 7 14 5 15 3 6 9 12 2 8 10 4
6 7 14 5 15 3 6 9 12 2 4 8 16
6 7 14 5 15 3 6 9 12 2 4 8 16
7 7 14 5 15 3 9 12 18 2 4 8 16 10 6
7 7 14 5 ...

result:

ok 1008 cases