This is the first day for you at your new job and your boss asks you to copy some files from one computer to other computers in an informatics laboratory. He wants you to finish this task as fast as possible. You can copy the files from one computer to another using only one Ethernet cable. Bear in mind that any File-copying process takes one hour, and you can do more than one copying process at a time as long as you have enough cables. But you can connect any computer to one computer only at the same time. At the beginning, the files are on one computer (other than the computers you want to copy them to) and you want to copy files to all computers using a limited number of cables.
First line of the input file contains an integer T (1 ≤ T ≤ 100) which denotes number of test cases. Each line in the next T lines represents one test case and contains two integers N, M.
N is the number of computers you want to copy files to them (1 ≤ N ≤ 1,000,000,000). While M is the number of cables you can use in the copying process (1 ≤ M ≤ 1,000,000,000).
For each test case, print one line contains one integer referring to the minimum hours you need to finish copying process to all computers.
3
10 10
7 2
5 3
4
4
3
一台电脑只能与另一台电脑连接,所以t*=2,当电线用完后,将以链接的电脑减去,不带复制m即可
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <map> #include <vector> #include <algorithm> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define PI 3.141592653589793238462 #define INF 0x3f3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int dp[1260]; int a[15],t; int main() { ll t,n,m; scanf("%lld",&t); while(t--) { scanf("%lld%lld",&n,&m); n; ll pos=0; ll ans=0; ll cnt=1; for(ll i=1;;i++) { if(m<=cnt) { cnt=m; ans++; pos+=cnt; if(pos>=n) { cout<<ans<<endl; break; } if((n-pos)%cnt==0) ans+=(n-pos)/cnt; else ans+=(n-pos)/cnt+1; cout<<ans<<endl; break; } ans++; pos+=cnt; if(pos>=n) { cout<<ans<<endl; break; } cnt*=2; } } return 0; }