Gym - 100952 B - New Job

Posted 浅忆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gym - 100952 B - New Job相关的知识,希望对你有一定的参考价值。

Statements

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.

Input

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).

Output

For each test case, print one line contains one integer referring to the minimum hours you need to finish copying process to all computers.

Example

Input
3
10 10
7 2
5 3
Output
4
4
3

Note

In the first test case there are 10 computer and 10 cables. The answer is 4 because in the first hour you can copy files only to 1 computer, while in the second hour you can copy files to 2 computers. In the third hour you can copy files to 4 computers and you need the fourth hour to copy files to the remaining 3 computers.

 1 #include <iostream>
 2 #define ll long long
 3 using namespace std;
 4 
 5 ll n,m;
 6 int main(){
 7     int t;
 8     cin>>t;
 9     while(t--){
10         ll ans=0;
11         cin>>n>>m;
12         ll g=1;
13         while(n>0){
14             if(g>=m){
15                 g=m;
16                 ans+=(n/m);
17                 if(n%m) ans++;
18                 break;
19             }
20             ans++;
21             n-=g;
22             g<<=1;
23         }
24         cout<<ans<<endl;
25     }
26     return 0;
27 }
 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 
 5 int main(){
 6     int t,ans=0;
 7     long long  a,b;
 8     while(~scanf("%d",&t))
 9     for(int i=0;i<t;i++){
10         scanf("%d%d",&a,&b);
11     for(int j=1;;j*=2){
12     if(a>j&&j<=b){
13         a-=j;
14         ans++;
15     }
16     else if(a<=j&&j<=b) {
17             ans++;
18             break;
19     }
20     else if(a>=j&&j>b) {
21         int c;
22         c=a/b;
23         ans=ans+c;
24         break;
25             }
26         }
27     printf("%d\n",ans);
28     }
29     return 0;
30 }

 

以上是关于Gym - 100952 B - New Job的主要内容,如果未能解决你的问题,请参考以下文章

codeforces gym 100952 A B C D E F G H I J

Gym - 100952D

Gym - 100952G

Gym - 100952H

Gym - 100952C

Gym - 100952G (博弈)