(Bestcoder Round #64 (Div.2)) Array--Bestcoder Round #64 (Div.2)

Source: Internet
Author: User

Bestcoder Round #64 (Div.2)

Array

Problem Description
Vicky is a math-loving magician with the ability to replicate and create. At first he had a sequence of {1}. Every day, he copies the sequence of his day, puts it at the end of the series, and divides it by 0 between the two series. Vicky wanted to make some changes, so he added all the new figures for the day (including 0) to 1. Vicky now want to test you, after 100 days, this series of the first m and how much?
Enter a description
Enter more than one set of data. The first line contains an integer t, which represents the number of data groups. T.\left (1 \leq T \leq 2 * {10}^{3} \right)(1≤T≤2∗10?3??The first row of each group of data contains an integer m.\left (1\leq M \leq {10}^{16} \right)< Span class= "Minner textstyle uncramped" > (1≤m≤< Span class= "Mord" >10 ?16 ?? )    /span>                
Output Description
For each set of data output a row of answers.
Input Sample
3135
Output Sample
147
Hint
The first item is always a number11, so sample 1 output11 The next day first copy, separated by 0, get {1,0,1}, and then add the resulting number 1, get {1,1,2}, so the sample 2 output the first 3 items and1+1+2=41+ 1+2=4. The third day first get { 1,1,2,0,1,1,2}, then get {1,1,2,1,2,2,3}, so sample 3 outputs the first 5 items and 1+1+2+1+2=71+1+2 +1+2= 7               

#include <stdio.h>#include<string.h>#defineN 110000#defineOO 0xFFFFFLong Longsum[ the], a[ the];Long LongFind (Long LongNintnn) {    if(nn<=0)        return 0; if(n<A[nn])returnFind (N, nn-1); Else if(n==A[nn])returnSum[nn]; Else    returnSUM[NN] + Find (n-a[nn]-1, nn) + N-a[nn];}intMain () {intI, nn; Long LongW =1e17; sum[1] =1, a[1] =1;  for(i=2; i< the; i++) {A[i]= a[i-1]*2+1; Sum[i]= sum[i-1]*2+ a[i-1] +1; if(a[i]>w) {nn=i;  Break; }    }    intT; scanf ("%d", &T);  while(t--)    {        Long LongN, ans; scanf ("%i64d", &N); Ans=Find (n, nn); printf ("%i64d\n", ans); }    return 0;}

(Bestcoder Round #64 (Div.2)) Array--Bestcoder Round #64 (Div.2)

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.