HDU 5587 Array Math problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.