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? InputThe first line is an integer K, indicating the number of samples. The next line is an integer, indicating X (0 ≤ X ≤ 10 ^ 18 ). OutputEach row outputs an integer, indicating the time required for Harry Potter to arrive at school. Sample Input3110100 Sample output159
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!
|