Array
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 119 Accepted Submission(s): 65
Problem Description
Vicky is a magician who loves math. She has great power in copying and creating.
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.
Input
There are multiple test cases.
First line contains a single integer T, means the number of test cases. (1≤T≤2∗103)
Next T line contains, each line contains one interger M. (1≤M≤1016)
First line contains a single integer T, means the number of test cases. (1≤T≤2∗103)
Next T line contains, each line contains one interger M. (1≤M≤1016)
Output
For each test case,output the answer in a line.
Sample Input
3 1 3 5
Sample Output
1 4 7
Source
出题人:
其实Ai为i二进制中1的个数。每次变化Ak+2i=Ak+1 ,(k<2i)不产生进位,
二进制1的个数加1。然后数位dp统计前m个数二进制1的个数,
计算每一位对答案的贡献。只需考虑该位填1,其高位与低位的种数即可。
我用搜索
先求出1,3,7,15。。。。。的前缀和( a[i] )及对应位置 (b[i] )
输入数n
再搜索3中情况
1 b[i]=n return a[i]
2 b[i]+1=n return a[i]+1
3 b[i]+1<n return a[i]+dfs(n-b[i]-1)+num-b[i];
#include
#include
#include
#include
#include