TOJ 3470.Key Integer

来源:互联网 发布:郸城县乡镇人口数据 编辑:程序博客网 时间:2024/06/07 03:44

题目链接:http://acm.tju.edu.cn/toj/showp3470.html


3470.   Key Integer
Time Limit: 4.0 Seconds   Memory Limit: 65536K
Total Runs: 211   Accepted Runs: 191



ZSJ likes travel, and sometimes his may find some place that unknow to people. Once he found such a place, he will tell his friend ZXT about this. A few days before, ZXT found a mysterious place. At this place, he saw a big stone-gate. Beside this gate, there are some mysterious letters that ZSJ can't read. So he drew these letters on a piece of paper and went back home to ask ZXT for help. After a few days of hard work, ZXT told ZSJ that : If he want to open the door, he must find the certain integer between 1 and N (inclusively) that fits a fixed condition, but she can't tell what the condition is because she can't understand all those mysterious letters. But the good news is: if ZSJ trys an integer k, he can get one of the three piece of information from the mysterious stone-door: k is just the number that required, k is smaller than the required integere and k is greater than the required integer. Knowing about this, ZSJ decide to use the following method to get the required integer:

x <- 1y <- Nwhile (true) {m <- (x+y)/2try the number m andif m is the required integer, breakif m is smaller, x = m + 1if m is greater, y = m - 1}
ZSJ is sure that he can get the required integer by the method mentioned above. But he has a question that when using this method, how many integers he has to try at most.

Input

The first line of input file is a sigle integer T, the number of test cases. Then T lines follows, each line contains a sigle integer N . Its meaning has mentioned above. (1 ≤ T ≤ 27; 1 ≤ N ≤ 100000).

Output

For each test cases, output a single integer: the number of integers he has to try at most.

Sample Input

210427

Sample Output

49

Hint: In the first test cases, the possible key integer to open the door is 1, 2, 3, 4, 5, 6, 7, 8, 9. If the key integer is 1, using the methord above, ZSJ has to try 3 integers: {5, 2, 1}; if the key integer is 2, he has to try: {5, 2}; and so on. When the key integer is 4, he has to try most integers: {5, 2, 3, 4}. So the answer of the first test case is 4.


水题不多bb:


#include <stdio.h>int main(){    int n,T;    scanf("%d",&T);    while(T--){        scanf("%d",&n);        int i = 1,k = 0;        while (i<n){            i *= 2;            k++;        }        printf("%d\n",k);    }    return 0;}



原创粉丝点击