UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214940#3855. 好数132704606091001568ms1192kbC++672b2024-11-24 11:05:402024-11-24 13:15:37

answer

#include <cstdio>
#include <iostream>
using namespace std;
int T;
long long l, r;
int popcnt(long long x) {
    int res = 0;
    for (; x; x ^= x & -x) res++;
    return res;
}
int calc(long long x) {
    int res = 0;
    for (; x; x >>= 1) res++;
    return res - 1;
}
int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%lld%lld", &l, &r);
        long long ans = l;
        while (popcnt(ans) > calc(ans & -ans) || popcnt(ans) + 1 == calc(ans & -ans)) ans += ans & -ans;
        if (popcnt(ans) < calc(ans & -ans))
            ans |= (1ll << popcnt(ans) + 1);
        printf("%lld\n", ans <= r ? ans : -1);
    }
    return 0;
}

详细

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

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 0ms
memory: 1192kb

input:

1
999995700 1000000000

output:

-1

result:

ok Accepted! >_<


Test #2:

score: 0
Accepted
time: 38ms
memory: 1188kb

input:

100000
7857167 7862247
8344618 8348655
8382478 8388566
8315927 8321011
8246290 8250342
8382480 83885...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
8370176
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok Accepted! >_<


Test #3:

score: 0
Accepted
time: 41ms
memory: 1188kb

input:

100000
3166357 3545086
7423160 8325545
9361438 9604609
5203715 5701815
8677014 9311476
6233360 68575...

output:

3166400
7423744
9361920
5204480
8677440
6234368
6950656
3018816
7941632
1635584
4227872
8719424
5778...

result:

ok Accepted! >_<


Test #4:

score: 0
Accepted
time: 30ms
memory: 1188kb

input:

100000
8250369 8255487
8119297 8124415
7857153 7862271
6284289 6289407
8373249 8378367
8365057 83701...

output:

-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:

ok Accepted! >_<


Test #5:

score: 0
Accepted
time: 39ms
memory: 1192kb

input:

100000
4183068 4187125
8115213 8119247
7332913 7337967
8373285 8378333
8246291 8250362
4183067 41871...

output:

-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:

ok Accepted! >_<


Test #6:

score: 0
Accepted
time: 42ms
memory: 1188kb

input:

100000
6511250 7509825
3016528 3835979
2753280 3654054
2828853 3543772
6676086 7585636
1336438 17936...

output:

6512128
3016768
2753344
2829056
6676736
1336704
1921792
3430144
1088064
7250176
5220864
4495744
1466...

result:

ok Accepted! >_<


Test #7:

score: 0
Accepted
time: 31ms
memory: 1192kb

input:

100000
8382464 8388611
7332864 7337983
8373248 8378367
8315904 8321023
4187136 4192255
8115200 81192...

output:

8382464
7332864
8373248
8315904
4187136
8115200
8360960
8378368
7853056
4183040
8107008
8303616
7320...

result:

ok Accepted! >_<


Test #8:

score: 0
Accepted
time: 42ms
memory: 1188kb

input:

100000
4187146 4192246
8348703 8353742
8378375 8382463
4183070 4187097
8360963 8365024
8344605 83486...

output:

-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:

ok Accepted! >_<


Test #9:

score: 0
Accepted
time: 40ms
memory: 1188kb

input:

100000
8803828 9608675
306374 314834
3032591 3831721
8888467 9081137
4801340 5285578
1056990 1788249...

output:

8804096
306560
3032832
8889088
4801408
1056992
3643904
2907392
8015360
8913856
6909440
6659584
11986...

result:

ok Accepted! >_<


Test #10:

score: 0
Accepted
time: 34ms
memory: 1192kb

input:

100000
8382465 8388612
7332865 7337984
8119297 8124416
6284289 6289408
8315905 8321024
4187137 41922...

output:

8388612
7337984
8124416
6289408
8321024
4192256
7332864
8250368
8119296
8315904
8365056
6284288
4187...

result:

ok Accepted! >_<


Test #11:

score: 0
Accepted
time: 38ms
memory: 1188kb

input:

100000
4187165 4192247
6284323 6289365
6284292 6289366
6284293 6289404
4183049 4187136
8315938 83210...

output:

-1
-1
-1
-1
4187136
-1
-1
-1
-1
-1
-1
-1
-1
4187136
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
8373248
-1
-1
-1
-...

result:

ok Accepted! >_<


Test #12:

score: 0
Accepted
time: 32ms
memory: 1188kb

input:

100000
4286975 4908307
9683477 9930904
8579514 9296546
3589230 4452606
2022097 2617062
9222988 93909...

output:

4287104
9683712
8579840
3589376
2023680
9223680
426688
3286400
7361152
4101632
1052680
8568864
54105...

result:

ok Accepted! >_<


Subtask #2:

score: 30
Accepted

Test #13:

score: 30
Accepted
time: 27ms
memory: 1192kb

input:

100000
8382464 8388612
7332864 7337984
8250368 8255488
8119296 8124416
8373248 8378368
8348672 83537...

output:

8382464
7332864
8250368
8119296
8373248
8348672
8315904
4187136
8246272
8311808
8344576
6280192
4174...

result:

ok Accepted! >_<


Test #14:

score: 0
Accepted
time: 50ms
memory: 1188kb

input:

100000
330807594 855120061
2739043 698283851
6893055 483485075
87223028 335275196
436165546 84345741...

output:

330813440
2739456
6893696
87223296
436166656
184620160
878068224
321856512
421955072
518016000
16218...

result:

ok Accepted! >_<


Test #15:

score: 0
Accepted
time: 48ms
memory: 1188kb

input:

100000
775803569 969702803
85461932 615601357
762866118 893251725
250087967 904974579
155037438 6394...

output:

775816192
85462144
762872832
250089984
155039744
271466624
606276864
614894080
378332160
634541056
2...

result:

ok Accepted! >_<


Test #16:

score: 0
Accepted
time: 52ms
memory: 1188kb

input:

100000
130615964 543185019
196269565 471109044
219486005 225290312
698409571 899750338
411258373 754...

output:

130617856
196270080
219486720
698412032
411259136
25559616
209125888
229261824
254457856
677872128
4...

result:

ok Accepted! >_<


Test #17:

score: 0
Accepted
time: 47ms
memory: 1188kb

input:

100000
255723571 895551031
508758301 569794703
40263079 330048659
113440683 868414377
950208385 9778...

output:

255727616
508759040
40263936
113442944
950209024
336073280
117272576
486799360
535764992
19296512
49...

result:

ok Accepted! >_<


Test #18:

score: 0
Accepted
time: 51ms
memory: 1192kb

input:

100000
104553077 989562637
10120318 724797962
158309830 678524578
557884646 983322572
58146931 97361...

output:

104555520
10120704
158312448
557885184
58147840
381737984
169214016
817199104
15508992
146796544
202...

result:

ok Accepted! >_<


Test #19:

score: 0
Accepted
time: 48ms
memory: 1188kb

input:

100000
453986044 643127299
62050080 325153194
213493974 507329641
169830974 860259287
330899407 7438...

output:

453990400
62051328
213497856
169834496
330900480
127203328
661805056
130289152
67767168
252281088
51...

result:

ok Accepted! >_<


Test #20:

score: 0
Accepted
time: 53ms
memory: 1192kb

input:

100000
59899167 304158243
44764825 925280222
175022152 410288846
263464485 665242780
351885365 95203...

output:

59899968
44765440
175023104
263469056
351889408
718854144
561412096
749109760
428626432
297998848
18...

result:

ok Accepted! >_<


Test #21:

score: 0
Accepted
time: 49ms
memory: 1188kb

input:

100000
247294342 765596808
22498929 72278665
409838880 678769102
330937103 851913510
431099294 51949...

output:

247296000
22499840
409843712
330942464
431100416
59854336
294649888
296293888
166901760
427741184
34...

result:

ok Accepted! >_<


Test #22:

score: 0
Accepted
time: 48ms
memory: 1192kb

input:

100000
609469149 937829398
741752 437102813
127563047 952873626
80617897 400333252
239724969 6302970...

output:

609471488
741760
127563776
80619008
239728640
517591040
285431040
282229760
897856000
289708288
1937...

result:

ok Accepted! >_<


Test #23:

score: 0
Accepted
time: 48ms
memory: 1192kb

input:

100000
365447063 782245369
485718533 809336092
328659366 905072830
4285772 26561306
232286466 967710...

output:

365447680
485722112
328663552
4285824
232290304
501157888
71807488
232544256
430618624
41154560
4663...

result:

ok Accepted! >_<


Test #24:

score: 0
Accepted
time: 44ms
memory: 1192kb

input:

100000
161998019 732149668
13514251 779577691
542181786 554173783
52348119 840210025
642210525 78738...

output:

161998848
13515264
542182016
52349952
642212864
46347776
637769216
205804288
147292416
301007104
338...

result:

ok Accepted! >_<


Subtask #3:

score: 40
Accepted

Test #25:

score: 40
Accepted
time: 52ms
memory: 1188kb

input:

100000
399579116 591906314
740833634 945801951
571383727 687256424
802141272 968687299
451896528 771...

output:

399582208
740833792
571384064
802161152
451907584
418344960
335120384
295351296
106297344
134602240
...

result:

ok Accepted! >_<


Test #26:

score: 0
Accepted
time: 46ms
memory: 1192kb

input:

100000
796860417 796901341
804724751 804765668
536821802 536870903
771694642 771735519
973021233 973...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
796860416
-1
-1
-1
-1
-1
-1
-1
805158912
-1
-1
-1
-1
-1
-1
-1...

result:

ok Accepted! >_<


Test #27:

score: 0
Accepted
time: 47ms
memory: 1188kb

input:

100000
143224219 144088533
256791488 257781238
543839423 544640061
942539426 943186316
716874801 717...

output:

143224320
256792576
543839744
942540288
716875776
321530368
218950656
417890560
711946240
14673920
4...

result:

ok Accepted! >_<


Test #28:

score: 0
Accepted
time: 38ms
memory: 1188kb

input:

100000
939474945 939524111
989798401 989839359
503259137 503300095
796860417 796901375
804724737 804...

output:

-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:

ok Accepted! >_<


Test #29:

score: 0
Accepted
time: 47ms
memory: 1192kb

input:

100000
931078162 931119072
536821766 536870881
536682515 536723417
536821806 536870893
973021205 973...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
796860416
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok Accepted! >_<


Test #30:

score: 0
Accepted
time: 55ms
memory: 1192kb

input:

100000
340633188 341332987
60400081 60442294
476731983 477175828
992672021 993450108
596640240 59706...

output:

340634624
60400128
476734464
992674816
596640384
510526464
76446720
899845120
420779520
304014336
59...

result:

ok Accepted! >_<


Test #31:

score: 0
Accepted
time: 31ms
memory: 1192kb

input:

100000
939474944 939524111
536821760 536870915
528424960 528465919
939204608 939245567
520036352 520...

output:

939474944
536821760
528424960
939204608
520036352
989798400
503259136
805183488
973021184
998187008
...

result:

ok Accepted! >_<


Test #32:

score: 0
Accepted
time: 50ms
memory: 1192kb

input:

100000
536821792 536870905
528425007 528465911
536748035 536788975
536289316 536330219
528424960 528...

output:

-1
-1
-1
-1
528424960
-1
805183488
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok Accepted! >_<


Test #33:

score: 0
Accepted
time: 52ms
memory: 1188kb

input:

100000
479266675 479640744
653516336 654473738
784390885 784940472
410201498 410578138
357486596 357...

output:

479267072
653525504
784393216
410203136
357488640
697188864
875498496
583324160
436928640
507807232
...

result:

ok Accepted! >_<


Test #34:

score: 0
Accepted
time: 41ms
memory: 1188kb

input:

100000
805257217 805306376
939204609 939245568
536289281 536330240
989798401 989839360
503259137 503...

output:

805306376
939245568
536330240
989839360
503300096
805224448
535805952
931119104
469745664
771735552
...

result:

ok Accepted! >_<


Test #35:

score: 0
Accepted
time: 62ms
memory: 1188kb

input:

100000
528425008 528465878
520036398 520077284
939204651 939245541
805257222 805306338
469704725 469...

output:

-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:

ok Accepted! >_<


Test #36:

score: 0
Accepted
time: 47ms
memory: 1192kb

input:

100000
877733125 878206664
184434749 184790814
546805355 547295380
287469447 287483492
325021440 325...

output:

877733376
184436736
546806784
287469824
325021696
513435648
95509504
117073920
747946496
924184576
4...

result:

ok Accepted! >_<


Test #37:

score: 0
Accepted
time: 28ms
memory: 1192kb

input:

100000
805257216 805306376
536821760 536870916
536289280 536330240
520036352 520077312
503259136 503...

output:

805257216
536821760
536289280
520036352
503259136
973021184
804724736
535764992
998187008
805117952
...

result:

ok Accepted! >_<


Extra Test:

score: 0
Extra Test Passed