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=1012 and 14=11102 equals to 3, since 0101 and 1110 differ in 3 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 0 to n. That’s strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.

Input
The input consists of multiple test cases. The first line contains one integer t (1≤t≤10000) — the number of test cases. The following t lines contain a description of test cases.

The first and only line in each test case contains a single integer n (1≤n≤1018).

Output
Output t 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 0, 1, …, n−1, n.

Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n=5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):

000
001
010
011
100
101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1+2+1+3+1=8.
思路:我们可以找找规律。
拿样例来说:
右数第一位,一共贡献了5个,也就是n/(2^0)
右数第二位,一共贡献了2个,也就是n/(2^1)
右数第三位,一共贡献了1个,也就是n/(2^2)
规律就很明显了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;ll n;int main()
{int t;scanf("%d",&t);while(t--){scanf("%lld",&n);ll ans=0;ll nn=n;ll i=1;while(nn){ans+=n/i;i<<=1ll;nn>>=1ll;}cout<<ans<<endl;}return 0;
}

努力加油a啊,(o)/~

Johnny and Another Rating Drop CodeForces - 1362C(规律)相关推荐

  1. 拆位 ---- C. Johnny and Another Rating Drop[位运算,计算每一位的贡献+推导过程]

    C. Johnny and Another Rating Drop 题目大意:就是定义一个不公平度就是相邻两个数的二进制位不相同数 比如说:100和011就是有3位不同 现在给你一个n∈[1,1e18 ...

  2. Yet Another Counting Problem CodeForces - 1342C(规律+前缀和)

    You are given two integers a and b, and q queries. The i-th query consists of two numbers li and ri, ...

  3. String Modification CodeForces - 1316B(规律)

    Vasya has a string s of length n. He decides to make the following modification to the string: Pick ...

  4. Codeforce Flea CodeForces - 32C 规律|思维

    题意 给我们一个n*m的表格 告诉我们每次跳跃的格子数量s 只能垂直或者水平跳跃 可以跳跃无限次 那么某格子能到达的不同格子的数量就是这个格子的值 求表格中值最大的格子的数量 分析 表面上看像是搜索 ...

  5. Maximum Subsequence Value CodeForces - 1365E(规律+暴力)

    Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting ...

  6. 拼题A打卡奖励 (25 分),1355D,1362C;

    7-2 拼题A打卡奖励 (25 分)(背包) 题意: 求,从 n 个物品中选(每个物品有体积 vi, 价值 wi ),总体积不超过 m 的最大价值? n≤1e3,m≤7e5,vi≤600,wi≤30n ...

  7. codeforces:1361(div1)1362(div2):总结

    文章目录 前言 1362-A. Johnny and Ancient Computer 解析 1362-B - Johnny and His Hobbies 解析 1362-C - Johnny an ...

  8. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)【A、B、C题】

    A. Contest for Robots 签到题,注意特判即可. #include <bits/stdc++.h> using namespace std; const int N=11 ...

  9. Codeforces Round #839 (Div. 3)

    Problem - G - Codeforces (1)题目大意 一个人想提升下棋的rating,但是他只能一轮一轮来,若是他大于或者等于对战的那个人的rating,他的rating就会加1,那个对战 ...

最新文章

  1. RapidFramework使用Oracle的步骤
  2. laravel实现读写分离
  3. phpcms 指定id范围 调用_Elasticsearch v7 中Java High-Level REST Client同步和异步调用
  4. byte数组转blob类型_Java类型相互转换byte[]类型,blob类型
  5. 源码编译搭建LAMP环境
  6. 三菱a系列motion软体_通化三菱Q00JCPU
  7. anr产生的原理如何避免(android)
  8. Sublime好看字体
  9. 女朋友生日,我送她网页相册,她感动的哭了(文中有惊喜)
  10. 华为实验一 智慧相册
  11. 2022年更新宠物 鼠 鱼 十二生肖 宠物养殖系统区块源码
  12. 为什么mysql的delete操作不释放磁盘空间
  13. POST请求返回:401 Unauthorized
  14. 最全面的全栈技术(成功绝非偶然)
  15. python对excel求和_Python 两个Excel文件对应位置求和并存储
  16. 《社会调查数据管理——基于Stata 14管理CGSS数据》一1.5 本书简介和使用说明...
  17. 如何用js求1~n的阶乘之和
  18. 小米8se android q,小米8 SE
  19. 【教你用傻瓜式免费软件做好本本电池监测】
  20. MIB Browser建立新的叶子节点

热门文章

  1. C# 泛型(Generic)
  2. 结构体和类的区别-Objective-C基础
  3. hive 结构metastone_基于MySQL元数据的Hive的安装和简单测试
  4. STM32F4+Wi-Fi+EDP 向 OneNet 上传数据
  5. java课程设计 博客园_java课程设计
  6. linux datetime,Python datetime模块示例详解
  7. python arp攻击_ARP欺骗——用Python实现道德黑客攻击的自动化
  8. aboboo 上一句 快捷键_锁定微信防别人偷看,苹果电脑上的微信有何不同?
  9. QT QML 在qml中自定义信号
  10. elasticsearc之mapping的介绍