AtCoder Beginner Contest 100-C

takkii
Music and Technology
2 min readAug 12, 2019

I want to become someone who can solve and explain coding problem. So I tried to explain AtCoder Problem.

Problem

Explanation

In this problem, “How many times snuke can divide by 2” is important.
In the operations, choosing “multiply a_i by 3” for every i is not allowed.
So in a operation, snuke must choose “divide a_i by 2” at least one time.

a_i must be an integer, so snuke can divide a_i by 2 if a_i is a multiple of 2.
a_i which multiplied by 3 is also integer.

So snuke should consider how many times he can divide a by 2.
In case that he wants to operate as many as possible,
in a operation he should divide one a by 2 , and the other a_i must be multiplied by 3.

So in the following code, I count the times how many times a_i can be divided by 2 and sum sum them.

Computational complexity is below.
A for-loop of N is O(n).
a_i is at most 10**9. how many times can be divided is O(log base 2 of 10**9).
so, computational complexity is O(n times log base 2 of 10**9).

My Submission

N = int(input())
a_list = list(map(int,input().split()))

cnt = 0
for a in a_list:
tmp_cnt = 0
while True:
if a % 2 == 0:
tmp_cnt += 1
a = int(a / 2)
else:
break
cnt += tmp_cnt

print(cnt)

--

--

takkii
Music and Technology

Competitive Programming, MachineLearning, Manga, Music, BoardGame.