TOJ 3470.Key Integer

题目链接: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 <- 1
	y <- N
	while (true) {
		m <- (x+y)/2

		try the number m and
			if m is the required integer, break
			if m is smaller, x = m + 1
			if 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

2
10
427

Sample Output

4
9

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值