QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137683#6728. To the ParkYarema#WA 28ms4828kbC++171.3kb2023-08-10 16:35:392023-08-10 16:35:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 16:35:42]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:4828kb
  • [2023-08-10 16:35:39]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 100447;
int d[N];
VI pr;
bool used[N];

int find(int x)
{
	if (pr[x] || x == 1) return -1;
	if (!used[x / d[x]])
		return x / d[x];
	int y = find(x / d[x]);
	if (y == -1 && !used[d[x]]) return d[x];
	return y;
}


void solve()
{
	int n;
	cin >> n;
	vector<PII> ans;
	RFOR (i, n + 1, 1)
	{
		if (pr[i] || used[i]) continue;
		int y = find(i);
		if (y != -1)
		{
			ans.PB({i, y});
			used[i] = used[y] = 1;
		}
	}
	FOR (i, 0, n + 1)
		used[i] = 0;
	cout << SZ(ans);
	FOR (i, 0, SZ(ans)) cout << ' ' << ans[i].F << ' ' << ans[i].S;
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	pr.assign(N, 1);
	FOR (i, 2, N)
	{
		if (pr[i])
		{
			d[i] = i;
			for (int j = i * 2; j < N; j += i)
			{
				if (d[j] == 0)
					d[j] = i;
				pr[j] = 0;
			}
		}
	}
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

詳細信息

Test #1:

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

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: 28ms
memory: 4828kb

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

result:

wrong answer Case #18: Participant has a worse answer