CF1661B.Getting Zero

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Suppose you have an integer vv . In one operation, you can:

  • either set v=(v+1)mod32768v = (v + 1) \bmod 32768
  • or set v=(2v)mod32768v = (2 \cdot v) \bmod 32768 .

You are given nn integers a1,a2,,ana_1, a_2, \dots, a_n . What is the minimum number of operations you need to make each aia_i equal to 00 ?

输入格式

The first line contains the single integer nn ( 1n327681 \le n \le 32768 ) — the number of integers.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 0ai<327680 \le a_i < 32768 ).

输出格式

Print nn integers. The ii -th integer should be equal to the minimum number of operations required to make aia_i equal to 00 .

输入输出样例

  • 输入#1

    4
    19 32764 10240 49

    输出#1

    14 4 4 15

说明/提示

Let's consider each aia_i :

  • a1=19a_1 = 19 . You can, firstly, increase it by one to get 2020 and then multiply it by two 1313 times. You'll get 00 in 1+13=141 + 13 = 14 steps.
  • a2=32764a_2 = 32764 . You can increase it by one 44 times: 32764327653276632767032764 \rightarrow 32765 \rightarrow 32766 \rightarrow 32767 \rightarrow 0 .
  • a3=10240a_3 = 10240 . You can multiply it by two 44 times: 1024020480819216384010240 \rightarrow 20480 \rightarrow 8192 \rightarrow 16384 \rightarrow 0 .
  • a4=49a_4 = 49 . You can multiply it by two 1515 times.
首页