QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243273#6728. To the ParkCipherxzc#WA 37ms4004kbC++201.1kb2023-11-07 23:48:392023-11-07 23:48:40

Judging History

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

  • [2023-11-07 23:48:40]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:4004kb
  • [2023-11-07 23:48:39]
  • 提交

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 used[N];

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

    cin >> T;
    while (T--){
        cin >> n;
        for (int i = 1; i <= n; i++){
            used[i] = false;
        }

        vector<pair<int, int>> ans;
        for (int i = n; i > 1; i--){
            if (used[i]){
                continue;
            }
            int res = 0;
            for (int j = i + i; j <= n; j += i){
                if (!used[j]){
                    res = j;
                }
            }
            if (res){
                used[i] = used[res] = true;
                ans.push_back(mp(i, res));
            }
        }

        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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 37ms
memory: 4004kb

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

result:

wrong answer Case #18: Participant has a worse answer