QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578355#9354. Justifying the Conjecturepsycho#TL 14ms7580kbC++201.4kb2024-09-20 18:34:592024-09-20 18:35:00

Judging History

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

  • [2024-09-20 18:35:00]
  • 评测
  • 测评结果:TL
  • 用时:14ms
  • 内存:7580kb
  • [2024-09-20 18:34:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define vc vector
#define pii pair <int, int>
#define int long long

const int inf = 1e9;


template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<bool> a(1e6 +5 );
    set<int> caluga;
    for (int i = 2; i < a.size(); ++i) {
        if (a[i]) continue;
        caluga.insert(i);
        for (int j = i * 2; j < a.size(); j += i) {
            a[j] = true;
        }
    }
    int t;
    cin >> t;
    map<int, int> ans;
    while (t--) {
        int n;
        cin >> n;
        if (ans.count(n)) {
            if (ans[n] == -1) {
                cout << -1 << '\n';
                continue;
            }
            cout << ans[n] << ' ' << n - ans[n] << '\n';
            continue;
        }
        ans[n] = -1;
        for (auto i : caluga) {
            if (n - i <= 1) break;
            if (caluga.count(n - i)) continue;
            ans[n] = i;
        }
        if (ans[n] == -1) {
            cout << -1 << '\n';
            continue;
        }
        cout << ans[n] << ' ' << n - ans[n] << '\n';

    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 7580kb

input:

3
4
6
7

output:

-1
2 4
3 4

result:

ok ok

Test #2:

score: -100
Time Limit Exceeded

input:

100000
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
8...

output:


result: