QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137676#6728. To the ParkYarema#WA 63ms5776kbC++171.2kb2023-08-10 16:29:112023-08-10 16:29:25

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:29:25]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:5776kb
  • [2023-08-10 16:29:11]
  • 提交

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[d[x]])
		return d[x];
	x /= d[x];
	if (!used[x]) return x;
	return find(x);
}


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});
	}
	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)
			{
				d[j] = i;
				pr[j] = 0;
			}
		}
	}
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

詳細信息

Test #1:

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

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: 63ms
memory: 5776kb

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

result:

wrong answer Case #8: Duplicate person 2