QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137853#6728. To the ParkYarema#AC ✓53ms4820kbC++171.3kb2023-08-10 18:23:232023-08-10 18:23:32

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 18:23:32]
  • 评测
  • 测评结果:AC
  • 用时:53ms
  • 内存:4820kb
  • [2023-08-10 18:23:23]
  • 提交

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

void solve()
{
	int n;
	cin >> n;
	vector<PII> ans;
	RFOR (i, n + 1, 2)
	{
		if (pr[i])
		{
			VI v;
			for (int j = i; j <= n; j += i)
				if (!used[j]) v.PB(j);
			if ((SZ(v) & 1) && SZ(v) > 1)
			{
				swap(v[1], v.back());
				v.pop_back();
			}
			FOR (j, 0, SZ(v) / 2)
			{
				used[v[j * 2]] = 1;
				used[v[j * 2 + 1]] = 1;
				ans.PB({v[j * 2], v[j * 2 + 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;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 53ms
memory: 4820kb

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

result:

ok 1008 cases