QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#260101#6728. To the ParkAH20WA 44ms4840kbC++141.8kb2023-11-21 20:00:542023-11-21 20:00:55

Judging History

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

  • [2023-11-21 20:00:55]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:4840kb
  • [2023-11-21 20:00:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e8+7;
const int maxm=1e5+7;
bitset<100000007>not_prime;
int prime[maxm],vis[maxm];
void check(int n){
	int tot=0;
	for(int i=2;i<=n;i++){
		if(not_prime[i]==0){
			prime[++tot]=i;
		}
		for(int j=1;j<=tot and i*prime[j]<=n;j++){
			not_prime[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	//cout<<tot<<endl;
}
void solve(){
    int n;cin>>n;
    if(n<=3){cout<<"0\n";return;}
    for(int i=1;i<=n;i++) vis[i] = 0;
    for(int i=1;i<=n;i++){
        if(i == 1) vis[i] = 1;
        if(!not_prime[i] and i*2>n){
            vis[i] = 1;
        }
    }
    //排除掉不可能结对的这些数字
    vector<array<int,2>>all;
    vector<int>left;
    for(int i=n;i>=1;i--){
        if(not_prime[i] or vis[i]) continue;
        //如果已经被占用了就直接跳过
        vector<int>tmp;
        for(int j=i;j<=n;j+=i){
            if(vis[j]) continue;
            vis[j] = 1;
            tmp.push_back(j);
        }
        int sz = tmp.size();
        if(sz%2 == 0){
            for(int i=0;i<sz;i+=2){
                all.push_back({tmp[i],tmp[i+1]});
            }
        }
        else{
            swap(tmp[1],tmp[0]);
            for(int i=1;i<sz;i+=2){
                all.push_back({tmp[i],tmp[i+1]});
            }
            left.push_back(tmp[0]);
        }
    }
    int sz = left.size();
    for(int i=0;i<sz;i+=2){
        all.push_back({left[i],left[i+1]});
    }
    cout<<all.size()<<" ";
    for(int i=0;i<all.size();i++){
        auto u = all[i];
        cout<<u[0]<<" "<<u[1];
        if(i+1 < all.size()) cout<<" ";
    }
    cout<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    check(maxm);
    int T;cin>>T;
    while(T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3692kb

input:

3
1
4
6

output:

0
1 2 4
2 3 6 2 4

result:

ok 4 cases

Test #2:

score: -100
Wrong Answer
time: 44ms
memory: 4840kb

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

result:

wrong answer Integer 0 violates the range [1, 8]