CF1362C.Johnny and Another Rating Drop

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.

The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5=10125 = 101_2 and 14=1110214 = 1110_2 equals to 33, since 01010101 and 11101110 differ in 33 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.

Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 00 to nn. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.

最近在 Johnny 最喜欢的编程竞赛平台上举办的上一场比赛获得了相当积极的评价。然而,Johnny 的评分(rating)再次下降了!他认为题目本身非常出色,但却无法真实反映参赛者的真实水平。

现在,Johnny 正在查看连续参赛者的评分,这些评分以二进制形式给出。他认为:两个相邻参赛者的评分二进制表示差异越大,将他们排在一起就越不公平。他将两个数之间的“差异”定义为:在相同长度(高位补零对齐后)的二进制表示下,一个数该位为 0 而另一个数该位为 1 的位置个数。例如,5=10125 = 101_2 与 14=1110214 = 1110_2 的差异为 33,因为将它们补零至等长后得到 01010101 和 11101110,二者在 33 个位置上满足上述条件。Johnny 将整场比赛的“不公平度”(unfairness)定义为:所有相邻参赛者评分对之间差异值的总和。

Johnny 刚刚把评分序列发给了你,希望你帮他计算这场比赛的不公平度。你注意到,收到的序列恰好是 00 到 nn 的连续整数。这看起来有些奇怪,但 Johnny 坚持认为一切无误。因此,请你帮他计算所给数字序列对应的不公平度。

输入格式

The input consists of multiple test cases. The first line contains one integer tt (1≤t≤10 0001 \leq t \leq 10\,000) — the number of test cases. The following tt lines contain a description of test cases.

The first and only line in each test case contains a single integer nn (1≤n≤1018)1 \leq n \leq 10^{18}).

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10 0001 \leq t \leq 10\,000),表示测试用例的数量。接下来的 tt 行描述了各个测试用例。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤10181 \leq n \leq 10^{18})。

输出格式

Output tt lines. For each test case, you should output a single line with one integer — the unfairness of the contest if the rating sequence equals to 00, 11, ..., n−1n - 1, nn.

输出 tt 行。对于每个测试用例,您应在一行中输出一个整数——即当评分为序列 00, 11, ..., n−1n - 1, nn 时,比赛的不公平度。

输入输出样例

  • 输入#1

    5
    5
    7
    11
    1
    2000000000000

    输出#1

    8
    11
    19
    1
    3999999999987

说明/提示

For n=5n = 5 we calculate unfairness of the following sequence (numbers from 00 to 55 written in binary with extra leading zeroes, so they all have the same length):

  • 000000
  • 001001
  • 010010
  • 011011
  • 100100
  • 101101

The differences are equal to 11, 22, 11, 33, 11 respectively, so unfairness is equal to 1+2+1+3+1=81 + 2 + 1 + 3 + 1 = 8.

当 n=5n = 5 时,我们计算如下序列的不公平度(将 00 到 55 的数字以二进制形式写出,并在前面补零,使它们长度相同):

  • 000000
  • 001001
  • 010010
  • 011011
  • 100100
  • 101101

相邻两项的差值分别为 11、22、11、33、11,因此不公平度为 1+2+1+3+1=81 + 2 + 1 + 3 + 1 = 8。

输入解题思路,AI测评打分。不知道怎么写?

首页