编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#25214 #2021. 玩genshin能验证哥德巴赫猜想吗? Accepted 100 231 ms 1572 K C++ 17 (Clang) / 1.3 K BAN 2024-12-21 19:53:36
显示原始代码
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

// 使用埃拉托斯特尼筛法计算素数
vector<bool> sieve(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;  // 0 和 1 不是素数
    for (int i = 2; i * i <= n; ++i) {
        if (is_prime[i]) {
            for (int j = i * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return is_prime;
}

int main() {
    int T;
    cin >> T;

    // 先读入所有的偶数,找出最大值,以便计算素数范围
    vector<int> numbers(T);
    int max_num = 0;
    for (int i = 0; i < T; ++i) {
        cin >> numbers[i];
        max_num = max(max_num, numbers[i]);
    }

    // 使用埃拉托斯特尼筛法生成所有小于等于max_num的素数
    vector<bool> is_prime = sieve(max_num);

    // 对每个输入的偶数进行处理
    for (int i = 0; i < T; ++i) {
        int even_num = numbers[i];

        // 找到两个素数 p 和 q,使得 p + q = even_num
        for (int p = 2; p <= even_num / 2; ++p) {
            if (is_prime[p] && is_prime[even_num - p]) {
                cout << p << " " << even_num - p << endl;
                break;
            }
        }
    }

    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:4 ms
内存:320 KiB

输入文件(test1.in

10
11882
19816
26170
32588
31402
8524
24028
26304
24708
1374

答案文件(test1.out

19 11863
3 19813
17 26153
19 32569
5 31397
3 8521
5 24023
7 26297
11 24697
7 1367

用户输出

19 11863
3 19813
17 26153
19 32569
5 31397
3 8521
5 24023
7 26297
11 24697
7 1367

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:4 ms
内存:328 KiB

输入文件(test2.in

10
12808
9558
16052
15158
17542
25098
31576
16206
21372
1968

答案文件(test2.out

17 12791
7 9551
19 16033
19 15139
3 17539
11 25087
3 31573
13 16193
31 21341
17 1951

用户输出

17 12791
7 9551
19 16033
19 15139
3 17539
11 25087
3 31573
13 16193
31 21341
17 1951

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:4 ms
内存:324 KiB

输入文件(test3.in

10
9728
12990
19500
7388
8
4680
13792
21246
24358
24220

答案文件(test3.out

7 9721
7 12983
11 19489
19 7369
3 5
7 4673
3 13789
19 21227
29 24329
17 24203

用户输出

7 9721
7 12983
11 19489
19 7369
3 5
7 4673
3 13789
19 21227
29 24329
17 24203

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:4 ms
内存:332 KiB

输入文件(test4.in

10
18718
4306
7742
6614
1826
31736
4222
15942
25996
17886

答案文件(test4.out

5 18713
17 4289
19 7723
7 6607
3 1823
7 31729
3 4219
5 15937
53 25943
5 17881

用户输出

5 18713
17 4289
19 7723
7 6607
3 1823
7 31729
3 4219
5 15937
53 25943
5 17881

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:4 ms
内存:320 KiB

输入文件(test5.in

10
10920
4720
25172
16358
22186
32346
5124
31430
9588
17924

答案文件(test5.out

11 10909
17 4703
3 25169
19 16339
29 22157
5 32341
5 5119
37 31393
37 9551
3 17921

用户输出

11 10909
17 4703
3 25169
19 16339
29 22157
5 32341
5 5119
37 31393
37 9551
3 17921

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:41 ms
内存:1564 KiB

输入文件(test11.in

10
5560704
6818396
44284
6045528
7489768
5116604
6570736
2315780
1866304
9438500

答案文件(test11.out

7 5560697
103 6818293
3 44281
7 6045521
29 7489739
7 5116597
5 6570731
7 2315773
3 1866301

<12 bytes omitted>

用户输出

7 5560697
103 6818293
3 44281
7 6045521
29 7489739
7 5116597
5 6570731
7 2315773
3 1866301
37 9438463

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:42 ms
内存:1572 KiB

输入文件(test12.in

10
2980380
5477462
6767948
6190360
9498642
1934814
4145748
3098576
592288
4234828

答案文件(test12.out

23 2980357
61 5477401
67 6767881
17 6190343
5 9498637
17 1934797
11 4145737
67 3098509
71 59
<17 bytes omitted>

用户输出

23 2980357
61 5477401
67 6767881
17 6190343
5 9498637
17 1934797
11 4145737
67 3098509
71 592217
5 4234823

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:40 ms
内存:1512 KiB

输入文件(test13.in

10
7478048
2001876
4257082
6909252
595066
1835210
9062504
188828
7382860
7931680

答案文件(test13.out

31 7478017
29 2001847
29 4257053
5 6909247
23 595043
79 1835131
13 9062491
37 188791
3 73828
<16 bytes omitted>

用户输出

31 7478017
29 2001847
29 4257053
5 6909247
23 595043
79 1835131
13 9062491
37 188791
3 7382857
47 7931633

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:33 ms
内存:1324 KiB

输入文件(test14.in

10
4028476
7041826
1652976
7556788
4756236
3945810
141620
3701714
2353844
4582800

答案文件(test14.out

5 4028471
257 7041569
29 1652947
131 7556657
53 4756183
7 3945803
7 141613
7 3701707
13 2353
<17 bytes omitted>

用户输出

5 4028471
257 7041569
29 1652947
131 7556657
53 4756183
7 3945803
7 141613
7 3701707
13 2353831
11 4582789

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:37 ms
内存:1444 KiB

输入文件(test15.in

10
8514752
2431888
6886872
2870762
7246634
2979644
2444570
5447566
4489872
1795000

答案文件(test15.out

3 8514749
47 2431841
29 6886843
61 2870701
97 7246537
61 2979583
13 2444557
23 5447543
11 44
<19 bytes omitted>

用户输出

3 8514749
47 2431841
29 6886843
61 2870701
97 7246537
61 2979583
13 2444557
23 5447543
11 4489861
17 1794983

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:18 ms
内存:872 KiB

输入文件(114.in

10
3807404
3807404
3807404
3807404
3807404
3807404
3807404
3807404
3807404
3807404

答案文件(114.out

751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 38066
<30 bytes omitted>

用户输出

751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653
751 3806653

系统信息

Exited with return code 0