QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137695#6728. To the ParkPetroTarnavskyi#AC ✓45ms7680kbC++171.3kb2023-08-10 16:40:442023-08-10 16:40:46

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:40:46]
  • 评测
  • 测评结果:AC
  • 用时:45ms
  • 内存:7680kb
  • [2023-08-10 16:40:44]
  • 提交

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 = 1 << 17;
VI vecs[N];
int u[N];

void solve(){
	int n;
	cin >> n;
	FOR(i, 1, n + 1){
		vecs[i].clear();
		u[i] = 0;
	}
	FOR(p, 3, n + 1){
		if(u[p] || p % 2 == 0)
			continue;
		vecs[p].PB(p);
		for(int j = 3 * p; j <= n; j += p)
			if(!u[j]){
				vecs[p].PB(j);
				u[j] = 1;
			}
	}
	int ans = 0;
	FOR(p, 3, n + 1){
		if(SZ(vecs[p]) % 2){
			if(2 * p <= n){
				vecs[p].PB(2 * p);
				u[2 * p] = 1;
			}
			else
				vecs[p].pop_back();
		}
		ans += SZ(vecs[p]) / 2;
	}
	FOR(i, 1, n + 1)
		if((i % 2 == 0) && !u[i])
			vecs[2].PB(i);
	if(SZ(vecs[2]) % 2)
		vecs[2].pop_back();
		
	ans += SZ(vecs[2]) / 2;
	
	cout << ans;
	FOR(p, 1, n + 1){
		for(int i : vecs[p])
			cout << " " << i;
	}
	cout << "\n";

}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t;
	cin >> t;
	while(t--)
		solve();
	
	
	return 0;
}

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

詳細信息

Test #1:

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

input:

3
1
4
6

output:

0
1 2 4
2 2 4 3 6

result:

ok 4 cases

Test #2:

score: 0
Accepted
time: 45ms
memory: 7680kb

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

result:

ok 1008 cases