cf Educational Codeforces Round 116 (Rated for Div. 2) B. Update Files

题目链接:Problem - 1606B - Codeforces

Berland State University has received a new update for the operating system. Initially it is installed only on the 11-st computer.

Update files should be copied to all nn computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.

Your task is to find the minimum number of hours required to copy the update files to all nn computers if there are only kk patch cables in Berland State University.

Input

The first line contains a single integer t (1≤t≤105) — the number of test cases.

Each test case consists of a single line that contains two integers n and k (1≤k≤n≤1018) — the number of computers and the number of patch cables.

Output

For each test case print one integer — the minimum number of hours required to copy the update files to all nn computers.

Example

input

Copy

4
8 3
6 6
7 1
1 1

output

Copy

4
3
6
0

Note

Let's consider the test cases of the example:

  • n=8, k=3:
    1. during the first hour, we copy the update files from the computer 1 to the computer 2;
    2. during the second hour, we copy the update files from the computer 1 to the computer 3, and from the computer 2 to the computer 4;
    3. during the third hour, we copy the update files from the computer 11 to the computer 5, from the computer 2 to the computer 6, and from the computer 3 to the computer 7;
    4. during the fourth hour, we copy the update files from the computer 2 to the computer 8.
  • n=6, k=6:
    1. during the first hour, we copy the update files from the computer 1 to the computer 2;
    2. during the second hour, we copy the update files from the computer 1 to the computer 3, and from the computer 2 to the computer 4;
    3. during the third hour, we copy the update files from the computer 1 to the computer 5, and from the computer 2 to the computer 6.
  • n=7, k=1:
    1. during the first hour, we copy the update files from the computer 1 to the computer 2;
    2. during the second hour, we copy the update files from the computer 1 to the computer 3;
    3. during the third hour, we copy the update files from the computer 1 to the computer 4;
    4. during the fourth hour, we copy the update files from the computer 4 to the computer 5;
    5. during the fifth hour, we copy the update files from the computer 4 to the computer 6;
    6. during the sixth hour, we copy the update files from the computer 3 to the computer 7.

题意:有k根数据线用来传输数据,一开始只有1台电脑有数据,传输一次需要1小时,问最多需要几小时才能让所有电脑都有数据

思路:刚开始有一台电脑,一小时后2台,之后每小时成倍增加,我们可以记录每个时间的电脑总数,然后多余的用除法计算

#include<bits/stdc++.h>
using namespace std;

map<long long, long long> mp;//用来记录有数据的电脑数量

int main(){
	int t;
	long long n, x;
	cin >> t;
	while(t--){
		cin >> n >> x;
		mp.clear();
		long long ans = 1;
		mp[0] = 1;
		if(n == 1){
			cout << 0 << endl;
			continue;
		}
		for(ans; ans; ans++){
			mp[ans] = mp[ans - 1] * 2;
			if(mp[ans] >= n){
				break;
			}
			if(mp[ans] >= x){
				break;
			}
			if(mp[ans] < 0){
				break;
			}
		}
		if(mp[ans] >= n){
			cout << ans << endl;
		}else{
			long long sum = ans;
			if((n - mp[ans]) % x != 0){
				sum++;
			}
			sum += (n - mp[ans]) / x;
			
			cout << sum << endl;
		}
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值