Logo Wy Online Judge

WyOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#474#94. 「NOIP2021」报数Pigsyy01402ms7556kbC++231.1kb2025-04-24 20:50:352025-04-24 20:50:36

answer

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool check(int x) {
    while (x) {
        if (x % 10 == 7) {
            return true;
        }

        x /= 10;
    }

    return false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    vector<int> queries(T);

    for (int i = 0; i < T; ++i) {
        cin >> queries[i];
    }

    int max_x = *max_element(queries.begin(), queries.end());
    int N = max_x + 100000;
    vector<bool> f(N, false);
    vector<int> nx(N, 0);
    int ls = 0;

    for (int i = 1; i < N; ++i) {
        if (f[i]) {
            continue;
        }

        if (check(i)) {
            for (int j = i; j < N; j += i) {
                f[j] = true;
            }

            continue;
        }

        nx[ls] = i;
        ls = i;
    }

    for (int x : queries) {
        if (x >= N || f[x]) {
            cout << "-1\n";
        } else {
            cout << nx[x] << "\n";
        }
    }

    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3492kb

input:

498
89 22
22 63
22 67
67 149
89 74
89 80
63 54
54 205
63 177
205 20
149 66
80 96
96 194
194 170
96 1...

output:

90
23
23
-1
23
-1
-1
151
90
-1
90
82
-1
-1
-1
206
-1
-1
206
22
151
69
82
99
99
-1
-1
-1
99
-1
22
-1
...

result:

wrong answer 1st words differ - expected: '1', found: '90'

Test #2:

score: 0
Wrong Answer
time: 4ms
memory: 3532kb

input:

496
376 35
35 334
35 49
376 328
35 184
334 9
184 216
35 50
49 108
9 79
79 274
9 325
274 416
416 272
...

output:

-1
-1
-1
-1
-1
-1
-1
330
-1
186
-1
10
186
-1
-1
52
-1
-1
10
-1
-1
-1
10
326
-1
418
418
-1
-1
-1
-1
1...

result:

wrong answer 1st words differ - expected: '7', found: '-1'

Test #3:

score: 0
Wrong Answer
time: 7ms
memory: 3408kb

input:

4996
58 212
212 251
251 501
251 358
58 483
501 200
212 173
501 21
501 34
34 506
483 266
173 144
266 ...

output:

59
215
215
253
253
-1
253
-1
59
-1
-1
202
215
-1
-1
-1
-1
-1
-1
509
-1
-1
-1
-1
-1
328
-1
115
115
-1...

result:

wrong answer 1st words differ - expected: '414', found: '59'

Test #4:

score: 0
Wrong Answer
time: 5ms
memory: 3460kb

input:

4997
599 56
599 83
56 283
56 292
283 764
283 148
56 770
83 251
83 362
362 199
770 871
362 448
871 48...

output:

601
-1
601
86
-1
286
-1
-1
286
-1
286
-1
-1
-1
86
253
86
363
363
200
-1
-1
363
-1
-1
-1
-1
842
200
8...

result:

wrong answer 1st words differ - expected: '427', found: '601'

Test #5:

score: 0
Wrong Answer
time: 7ms
memory: 3528kb

input:

5000
130 241
241 561
561 17
130 208
130 444
208 437
208 362
437 325
325 419
325 47
325 629
362 487
6...

output:

131
242
242
-1
-1
-1
131
209
131
-1
209
-1
209
363
-1
326
326
421
326
-1
326
-1
363
-1
-1
615
363
28...

result:

wrong answer 1st words differ - expected: '406', found: '131'

Test #6:

score: 0
Wrong Answer
time: 26ms
memory: 4288kb

input:

100000
1 89135
89135 42606
42606 51140
51140 88708
88708 24332
24332 42871
42871 42697
42697 49402
4...

output:

2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
60063
60063
-1
-1
48038
48038
46329
46329
-1...

result:

wrong answer 1st words differ - expected: '2309', found: '2'

Test #7:

score: 0
Wrong Answer
time: 33ms
memory: 4304kb

input:

100000
1 9530
9530 22076
22076 39846
39846 47126
47126 11168
11168 31227
31227 92667
92667 73020
730...

output:

2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st words differ - expected: '3467', found: '2'

Test #8:

score: 0
Wrong Answer
time: 31ms
memory: 4240kb

input:

100000
1 56545
56545 4442
4442 30021
30021 12958
12958 3882
3882 81161
81161 17303
17303 59356
59356...

output:

2
56549
56549
4443
4443
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1280
1280
-1
-1
-1
-1
-1
-1
9343
9...

result:

wrong answer 1st words differ - expected: '6159', found: '2'

Test #9:

score: 0
Wrong Answer
time: 28ms
memory: 4228kb

input:

100000
1 28773
28773 60979
60979 62259
62259 23921
23921 94894
94894 14535
14535 25483
25483 15766
1...

output:

2
-1
-1
-1
-1
-1
-1
23924
23924
-1
-1
-1
-1
-1
-1
-1
-1
61
61
69529
69529
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st words differ - expected: '2311', found: '2'

Test #10:

score: 0
Wrong Answer
time: 106ms
memory: 7416kb

input:

500000
1 266014
266014 196927
196927 19617
19617 450868
450868 244252
244252 69345
69345 240592
2405...

output:

2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st words differ - expected: '13932', found: '2'

Test #11:

score: 0
Wrong Answer
time: 83ms
memory: 7368kb

input:

500000
1 278484
278484 369808
369808 117284
117284 296213
296213 395873
395873 259275
259275 43124
4...

output:

2
-1
-1
-1
-1
-1
-1
296215
296215
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 1st words differ - expected: '18403', found: '2'

Test #12:

score: 0
Wrong Answer
time: 96ms
memory: 7456kb

input:

500000
1 402048
402048 181762
181762 153002
153002 57994
57994 330080
330080 309815
309815 101203
10...

output:

2
-1
-1
-1
-1
-1
-1
-1
-1
330082
330082
-1
-1
101204
101204
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
4802...

result:

wrong answer 1st words differ - expected: '12167', found: '2'

Test #13:

score: 0
Wrong Answer
time: 107ms
memory: 7556kb

input:

500000
1 404040
404040 422879
422879 251314
251314 437072
437072 166277
166277 496632
496632 137251
...

output:

2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
141263
141263
122839
122839
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st words differ - expected: '53754', found: '2'

Test #14:

score: 0
Wrong Answer
time: 93ms
memory: 6360kb

input:

500000
945 968
968 931
968 52
931 923
945 696
696 900
696 180
696 8
52 581
900 867
900 629
581 453
4...

output:

-1
982
982
-1
982
53
-1
-1
-1
-1
-1
-1
-1
181
-1
9
53
-1
-1
-1
-1
-1
-1
458
458
605
605
410
605
163
...

result:

wrong answer 1st words differ - expected: '3848', found: '-1'

Test #15:

score: 0
Wrong Answer
time: 82ms
memory: 6264kb

input:

500000
668 773
668 181
181 92
773 267
181 471
92 260
92 455
455 574
267 298
455 81
574 838
838 434
8...

output:

-1
-1
-1
183
183
93
-1
-1
183
-1
93
262
93
-1
-1
-1
-1
299
-1
-1
-1
839
839
-1
-1
341
341
496
341
-1...

result:

wrong answer 1st words differ - expected: '4', found: '-1'

Test #16:

score: 0
Wrong Answer
time: 91ms
memory: 6428kb

input:

500000
146 93
146 98
146 171
93 12
146 52
52 237
12 279
279 36
171 189
52 243
237 122
122 25
122 212...

output:

-1
95
-1
-1
-1
-1
95
13
-1
53
53
-1
13
-1
-1
38
-1
-1
53
-1
-1
123
123
26
123
215
123
122
-1
121
215...

result:

wrong answer 1st words differ - expected: '329', found: '-1'

Test #17:

score: 0
Wrong Answer
time: 33ms
memory: 3940kb

input:

100000
9 271
9 115
115 270
271 234
9 136
136 22
9 134
115 196
22 195
196 52
22 151
22 268
134 11
268...

output:

10
-1
10
116
116
-1
-1
-1
10
-1
-1
23
10
-1
116
-1
23
198
-1
53
23
155
23
-1
-1
12
-1
-1
-1
195
-1
6...

result:

wrong answer 1st words differ - expected: '4848', found: '10'

Test #18:

score: 0
Wrong Answer
time: 28ms
memory: 4008kb

input:

100000
38 135
38 114
38 155
135 645
38 52
135 593
155 491
645 251
593 245
491 40
52 269
245 622
40 3...

output:

39
-1
39
-1
39
159
-1
649
39
53
-1
596
159
492
649
253
596
-1
492
41
53
281
-1
625
41
-1
281
-1
253
...

result:

wrong answer 1st words differ - expected: '668', found: '39'

Test #19:

score: 0
Wrong Answer
time: 25ms
memory: 3888kb

input:

100000
255 350
255 14
14 222
14 415
222 40
415 232
14 65
40 174
222 438
65 29
232 152
232 261
261 20...

output:

-1
-1
-1
-1
-1
-1
-1
416
-1
41
416
233
-1
66
41
-1
-1
-1
66
30
233
-1
233
-1
-1
206
206
130
-1
38
-1...

result:

wrong answer 1st words differ - expected: '3757', found: '-1'

Test #20:

score: 0
Wrong Answer
time: 29ms
memory: 3964kb

input:

100000
880 278
278 659
278 211
659 509
659 270
659 634
659 819
819 501
659 474
474 11
474 221
270 69...

output:

-1
-1
-1
660
-1
212
660
512
660
-1
660
-1
660
-1
-1
-1
660
-1
-1
12
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st words differ - expected: '1', found: '-1'

Test #21:

score: 0
Wrong Answer
time: 96ms
memory: 6340kb

input:

500000
9 278
278 66
9 410
278 580
580 5
5 609
410 610
410 44
609 632
44 304
5 210
632 692
610 529
63...

output:

10
-1
-1
69
10
412
-1
583
583
6
6
-1
412
613
412
45
-1
-1
45
-1
6
-1
-1
-1
613
530
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st words differ - expected: '3', found: '10'

Test #22:

score: 0
Wrong Answer
time: 86ms
memory: 6312kb

input:

500000
471 528
471 418
471 256
418 18
18 64
18 461
256 577
577 167
64 537
461 273
64 154
64 354
354 ...

output:

-1
-1
-1
419
-1
258
419
19
19
65
19
463
258
-1
-1
-1
65
-1
463
-1
65
-1
65
-1
-1
526
-1
523
526
-1
-...

result:

wrong answer 1st words differ - expected: '9828', found: '-1'

Test #23:

score: 0
Wrong Answer
time: 99ms
memory: 6352kb

input:

500000
261 10
261 301
261 180
10 241
241 498
498 265
261 388
388 561
241 25
265 331
265 63
561 156
2...

output:

-1
11
-1
-1
-1
181
11
242
242
499
499
269
-1
-1
-1
-1
242
26
269
332
269
-1
-1
-1
269
-1
-1
502
332
...

result:

wrong answer 1st words differ - expected: '7813', found: '-1'

Test #24:

score: 0
Wrong Answer
time: 96ms
memory: 6336kb

input:

500000
12 21
12 30
21 53
21 58
12 75
53 14
30 40
14 72
53 26
58 67
75 42
14 66
14 29
72 71
42 49
71 ...

output:

13
-1
13
31
-1
55
-1
59
13
-1
55
-1
31
41
-1
-1
55
29
59
-1
-1
-1
-1
69
-1
30
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 1st words differ - expected: '8486', found: '13'

Test #25:

score: 0
Wrong Answer
time: 109ms
memory: 6264kb

input:

500000
43 28
28 2
2 49
28 12
43 18
49 45
2 34
28 41
18 3
12 5
34 24
5 44
41 16
24 47
5 36
24 7
44 48...

output:

44
-1
-1
3
3
-1
-1
13
44
19
-1
46
3
-1
-1
43
19
4
13
6
-1
25
6
45
43
18
25
-1
6
38
25
-1
45
50
-1
26...

result:

wrong answer 1st words differ - expected: '219', found: '44'