Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Bits – Kattis, Kattis https://open.kattis.

com/problems/bits

 Due to a performance problem scoring is currently being


updated slowly. We are working on it!

Bits
As we all know, it takes more energy to store binary numbers with lots of
ones in them. Yraglac’s calculator has some batteries that are almost dead,
and he’s concerned that the battery may run out as he types in a number.

The way the calculator processes numbers being entered is as follows.


Initially, the calculator stores the number zero in a 32-bit internal register.
As Yraglac types in each digit of his number, the register updates to store
the number entered thus far. For example, when Yraglac enters the number
94, the register stores the number 9 (binary 1001) after the �rst key is
pressed. When he presses the second key, the register clears itself and stores
the number 94 (binary 1011110). What is the maximum number of one-bits
in the register as Yraglac enters a number digit-by-digit?

To convert an integer x to a binary string, you can use


Integer.toBinaryString(x) in Java and bin(x) in Python. See the language
documentation for more information.

Input

The �rst line contains a single integer T ≤ 1 000 giving the number of test
cases. Each test case consists of a line with a single integer X (0 ≤ X < 231
), the number Yraglac wants to enter.

Output

For each test case, output a single line containing the maximum number of
one-bits in the storage register as the number X is entered, digit by digit.

1 of 3 31/03/2023, 06:09
Bits – Kattis, Kattis https://open.kattis.com/problems/bits

Sample Input 1 Sample Output 1

6 1
1 1
2 2
3 1
4 2
10 5
94

2 of 3 31/03/2023, 06:09
Bits – Kattis, Kattis https://open.kattis.com/problems/bits

CPU Time limit 1 second

Memory limit 1024 MB

Erfiðleiki 2.6 Easy

Feng ið frá Alberta Collegiate Programming Contest 2016

Leyfi For educational use only

3 of 3 31/03/2023, 06:09

You might also like