http://www.elijahqi.win/archives/2945
题目描述
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of
n
n vertices numbered from
0
0 to
n-1
n−1 . For all 0<=u<v<n 0<=u<v<n
u
u and vertex
v
v are connected with an undirected edge that has weight (where is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?
You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graph
You can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_tree
The weight of the minimum spanning tree is the sum of the weights on the edges included in it.
输入输出格式
输入格式:
The only line contains an integer
n
n
(2<=n<=10^{12})
(2<=n<=1012) , the number of vertices in the graph.
输出格式:
The only line contains an integer
x
x , the weight of the graph’s minimum spanning tree.
输入输出样例
输入样例#1: 复制
4
输出样例#1: 复制
4
说明
In the first sample: The weight of the minimum spanning tree is 1+2+1=4.
很有趣的一题 模拟kruskal的过程 手玩即可发现每次我的每个二进制位会贡献当前总数/2这么多的贡献 然后也相当于合并了这么些连通块 然后用总数减去合并的这些连通块再重复以上步骤