EXAMPLE
INPUT
4
8 3
6 6
7 1
1 1
output
4
3
6
0
题意
t个样例,每次包括正整数n,k表示n台电脑,最多同时传输数量是k。初始电脑1有数据,一台电脑在1个时间内可以传输到一台无数据的电脑,问最少需要多少时间传输数据到所有电脑。
思路
如果没有k的限制,时间1有2台,时间2有4台,时间x有2的x次方台,
当2的x次方大于k,同一时间只能最多传输k台
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5;
int main()
{
int t;
scanf("%d", &t);
ll ans = 0;
ll tem = 1;
ll n, k;
while (t--)
{
ans = 0;
tem = 1;
scanf("%lld%lld", &n, &k);
n -= tem;
while (tem <= k && n)
{
if (n > tem)
n -= tem;
else
break;
ans++;
tem *= 2;
}
if (tem > k)
tem = k;
ans += n / k;
if (n % k != 0)
ans++;
printf("%lld\n", ans);
}
return 0;
}