QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#243414#6728. To the ParkCipherxzcAC ✓39ms7740kbC++202.2kb2023-11-08 10:19:262023-11-08 10:19:26

Judging History

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

  • [2023-11-08 10:19:26]
  • 评测
  • 测评结果:AC
  • 用时:39ms
  • 内存:7740kb
  • [2023-11-08 10:19:26]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define mp make_pair

const int N = 1e5 + 5;
int T, n;
bool notp[N], used[N];
vector<int> p, num[N];

void Euler(int lim){
    for (int i = 2; i <= lim; i++){
        if (!notp[i]){
            p.push_back(i);
            num[p.size() - 1].push_back(i);
        }
        for (int j = 0; j < p.size() && p[j] <= lim / i; j++){
            notp[i * p[j]] = true;
            num[j].push_back(i * p[j]);
            if (i % p[j] == 0){
                break;
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    Euler(1e5);

    // for (int i = 0; i < p.size(); i++){
    //     for (int j: num[i]){
    //         cout << j << ' ';
    //     }
    //     cout << endl;
    // }

    cin >> T;
    while (T--){
        cin >> n;
        for (int i = 2; i <= n; i += 2){
            used[i] = false;
        }
        
        vector<pair<int, int>> ans;
        vector<int> vec;
        for (int i = 1; i < p.size() && p[i] * 2 <= n; i++){
            vec.clear();
            for (int j = 0; j < num[i].size() && num[i][j] <= n; j++){
                vec.push_back(num[i][j]);
            }
            int j = 0;
            if (vec.size() & 1){
                ans.push_back(mp(vec[0], vec[0] << 1));
                used[vec[0] << 1] = true;
                j = 1;
            }
            for (; j < vec.size(); j += 2){
                ans.push_back(mp(vec[j], vec[j + 1]));
            }
        }
        vec.clear();
        for (int x: num[0]){
            if (x > n){
                break;
            }
            if (!used[x]){
                vec.push_back(x);
            }
        }
        for (int i = 0; i + 1 < vec.size(); i += 2){
            ans.push_back(mp(vec[i], vec[i + 1]));
        }

        if (ans.size() == 0){
            cout << ans.size() << endl;
        }else{
            cout << ans.size() << ' ';
            for (int i = 0; i < ans.size(); i++){
                cout << ans[i].first << ' ' << ans[i].second << " \n"[i == ans.size() - 1];
            }
        }
    }

    return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 6808kb

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: 39ms
memory: 7740kb

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

result:

ok 1008 cases