Array
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=5587
Description
Vicky is a magician who loves math. She has the great power in copying and creating.
One day she gets a array {1}. After this, every day she copies all the numbers in the arrays she had, and puts them into the tail of the array, with a s Ignle ' 0 ' to Separat.
Vicky wants to make difference. So every number which is made today (include the 0) would be a plused by one.
Vicky wonders after (), what is the sum of the first M numbers.
Input
There is multiple test cases.
First line contains a single integer T, means the number of test cases.(1≤T≤2∗3)
Next T line contains, each line contains one Interger M.(1≤M≤)
Output
For each test case,output the answer with a line.
Sample Input
3 1 3 5
Sample Output
1 4 7
HINT
Test instructions
Exercises
Math Problem (:
First, we first use the law to figure out the total number of days I can get: g (i) =g (i-1) +2^ (i-1)
And then we can solve it recursively, using a power of 2 to recursively
Code:
#include <iostream>#include<stdio.h>#include<vector>#include<algorithm>#include<cstring>using namespaceStd;vector<Long Long>Q;Long LongAns =0;Long Longg[ the];voidSolveLong Longk) { if(k<=0)return; intp =--upper_bound (Q.begin (), Q.end (), K)-Q.begin (); Ans+=g[p]+k-Q[p]; Solve (k-q[p]-1);}intMain () {Long Longt=2; Q.push_back (0); for(intI=1; i<= -; i++) {q.push_back (T-1);//2^i-1 T*=2; } g[1]=1;Long Longtmp=2; for(intI=2; I<=q.size (); i++) {G[i]=2*g[i-1]+tmp;//saved is the answer to the day TMP=tmp*2; } intT;SCANF ("%d",&t); for(intI=1; i<=t;i++) { Long LongX;SCANF ("%i64d",&x); Ans=0; Solve (x); printf ("%i64d\n", ans); }}
HDU 5587 Array Math problem