Submission details
Task:Sum of ones
Sender:aalto26em_005
Submission time:2026-09-28 16:39:05 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.04 sdetails
#50.04 sdetails
#60.04 sdetails
#70.04 sdetails
#80.04 sdetails
#90.04 sdetails
#100.04 sdetails
#110.04 sdetails
#120.04 sdetails
#130.04 sdetails
#140.04 sdetails
#150.04 sdetails
#160.04 sdetails
#170.04 sdetails
#180.04 sdetails
#190.04 sdetails
#200.04 sdetails
#210.04 sdetails

Code

def count_total_ones(n):
    total_ones = 0
    bit_position = 0
    total_numbers = n + 1 
    
    while (1 << bit_position) <= n:
        #pattern=2x
        block_size = 1 << bit_position
        cyclelen = block_size * 2
        fullcycle = total_numbers // cyclelen
        full_1s = fullcycle * block_size

        #remaining
        leftover = total_numbers % cyclelen
        
        #they'll be 1s
        remaining = max(0, leftover - block_size)

        total_ones += full_1s + remaining
        bit_position += 1
        
    return total_ones

Test details

Test 1

Verdict:

input
1

correct output
1

user output
(empty)

Feedback: Output is shorter than expected

Test 2

Verdict:

input
2

correct output
2

user output
(empty)

Feedback: Output is shorter than expected

Test 3

Verdict:

input
3

correct output
4

user output
(empty)

Feedback: Output is shorter than expected

Test 4

Verdict:

input
4

correct output
5

user output
(empty)

Feedback: Output is shorter than expected

Test 5

Verdict:

input
5

correct output
7

user output
(empty)

Feedback: Output is shorter than expected

Test 6

Verdict:

input
6

correct output
9

user output
(empty)

Feedback: Output is shorter than expected

Test 7

Verdict:

input
7

correct output
12

user output
(empty)

Feedback: Output is shorter than expected

Test 8

Verdict:

input
8

correct output
13

user output
(empty)

Feedback: Output is shorter than expected

Test 9

Verdict:

input
9

correct output
15

user output
(empty)

Feedback: Output is shorter than expected

Test 10

Verdict:

input
10

correct output
17

user output
(empty)

Feedback: Output is shorter than expected

Test 11

Verdict:

input
303021765044187

correct output
7250167017244884

user output
(empty)

Feedback: Output is shorter than expected

Test 12

Verdict:

input
390977392667778

correct output
9400236781929604

user output
(empty)

Feedback: Output is shorter than expected

Test 13

Verdict:

input
670904313808571

correct output
16399391652009372

user output
(empty)

Feedback: Output is shorter than expected

Test 14

Verdict:

input
704275111916256

correct output
17252936460583174

user output
(empty)

Feedback: Output is shorter than expected

Test 15

Verdict:

input
799807335176164

correct output
19646099779305746

user output
(empty)

Feedback: Output is shorter than expected

Test 16

Verdict:

input
852012055430877

correct output
21005540865890493

user output
(empty)

Feedback: Output is shorter than expected

Test 17

Verdict:

input
901305628563213

correct output
22232965316761961

user output
(empty)

Feedback: Output is shorter than expected

Test 18

Verdict:

input
917427461591619

correct output
22650112032503064

user output
(empty)

Feedback: Output is shorter than expected

Test 19

Verdict:

input
981787468874797

correct output
24322274256024775

user output
(empty)

Feedback: Output is shorter than expected

Test 20

Verdict:

input
1000000000000000

correct output
24784747400675348

user output
(empty)

Feedback: Output is shorter than expected

Test 21

Verdict:

input
989898989898989

correct output
24531282955144033

user output
(empty)

Feedback: Output is shorter than expected