Xtu oj 1160 Harry Potter

Source: Internet
Author: User

Zookeeper

Harry Potter
Accepted: 72 Submit: 223
Time Limit: 1000 MS Memory Limit: 65536 KB

Description

Harry Potter wants to immediately arrive at the school. If he is in a straight line with the school, he is at first and the school is. In a unit of time, he can move one cell forward, or use magic to change himself to the current coordinate of two times. How long does it take for him to arrive at school?

Input

The first line is an integer K, indicating the number of samples. The next line is an integer, indicating X (0 ≤ X ≤ 10 ^ 18 ).

Output

Each row outputs an integer, indicating the time required for Harry Potter to arrive at school.

Sample Input
3110100
Sample output
159


In the last simulated training, the competition will be held next week. I had a joint training question from Xiangtan University. I was so frustrated that I only made one question. I had no idea how many questions I had, how can I go to the competition in this status !!! I only made this question. The following question has been wa for many times and has timed out several times. Many template questions cannot be seen as a template, there are still a lot of unfamiliar content !! I found a lot of problems, indicating that my strength is not good !!! More training is required !!

The following is the ac code:

#include 
     
      #include 
      
       using namespace std;int main(){    int t;    long long x;    scanf("%d",&t);    while(t--)    {        long long count=0;        scanf("%I64d",&x);        while(x)        {            if(x%2==0)            {                x/=2;                count++;            }            else            {                x-=1;                count++;            }        }        printf("%I64d\n",count);    }    return 0;}
      
     
You can use & 1 to determine whether it is an odd or even number, which may save time! Bit operation!

Related Article

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.