QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695158#6728. To the ParkShuishui#WA 41ms5292kbC++141.7kb2024-10-31 19:26:112024-10-31 19:26:13

Judging History

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

  • [2024-10-31 19:26:13]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:5292kb
  • [2024-10-31 19:26:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define Sz(x) (int)(x).size()
#define bit(x) (1ll << (x))
using ll = long long;
using db = double;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vd = vector<db>;
mt19937 mrand(time(0));

vector<int> p, pr;
int tot;

void sieve(int n) {
    p.assign(n + 1, 0);
    pr.clear();
    
    for (int i = 2; i <= n; i++) {
        if (!p[i]) p[i] = i, pr.push_back(i);
        for (auto v : pr) {
            if (i * v > n) break;
            p[i * v] = v;
            if (v == p[i]) break;
        }
    }
    tot = (int)pr.size();
}


void solve(void)
{
	int n;
	cin >> n;
	sieve(n);
	vi vis(n + 2);
	vector<array<int, 2>> ans;
	reverse(all(pr));

	auto match = [&](int x, int y)
	{
		vis[x] = vis[y] = 1;
		ans.pb({x, y});
	};
	for (auto d : pr)
	{
		int p = 0;
		for (int i = d; i <= n; i += d)
			if (i & 1 && !vis[i])
			{
				if (p)
				{
					match(i, p);
					p = 0;
				}
				else
					p = i;
			}
	}

	for (auto d : pr)
	{
		int p = 0;
		for (int i = d; i <= n; i += d)
			if (!vis[i])
			{
				if (p)
				{
					match(i, p);
					p = 0;
				}
				else
					p = i;
			}
	}


	int m = Sz(ans);
	cout << m << " \n"[m == 0];
	for (int i = 0; i < m; i++)
		cout << ans[i][0] << " " << ans[i][1] << " \n"[i == m - 1];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// cout << fixed << setprecision(10);

	int T = 1;
	cin >> T;
	for (int i = 1; i <= T; i++)
	solve();

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3944kb

input:

3
1
4
6

output:

0
1 4 2
2 6 3 4 2

result:

ok 4 cases

Test #2:

score: -100
Wrong Answer
time: 41ms
memory: 5292kb

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

result:

wrong answer Case #25: Participant has a worse answer