HDU 5587 Array

难以描述。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn=100+10;
int T;
long long M;
long long tot[maxn],sum[maxn];

int main()
{
    sum[1]=1;tot[1]=1;
    for(int i=2;i<=100;i++)
    {
        tot[i]=2*tot[i-1]+1;
        sum[i]=2*sum[i-1]+tot[i]-tot[i-1];
    }
    scanf("%d",&T);
    while(T--)
    {
        scanf("%I64d",&M);
        long long nowLen=M;
        long long ans=0;
        while(1)
        {
            for(int i=1;i<=100;i++)
            {
                if(tot[i]>nowLen)
                {
                    ans=ans+sum[i-1];
                    ans+=nowLen-tot[i-1];
                    nowLen=nowLen-tot[i-1];
                    nowLen-=1;
                    break;
                }
            }
            if(nowLen<=0) break;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

 

posted @ 2015-11-28 22:30  Fighting_Heart  阅读(112)  评论(0编辑  收藏  举报