前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】

Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】

作者头像
Angel_Kitty
发布2018-04-09 15:22:47
5110
发布2018-04-09 15:22:47
举报

B. New Job

time limit per test:1 second

memory limit per test:64 megabytes

input:standard input

output:standard output

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.

Examples

Input

代码语言:javascript
复制
3
10 10
7 2
5 3

Output

代码语言:javascript
复制
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.

题目链接:http://codeforces.com/gym/100952/problem/B

题意:将一个文件复制到n台电脑上,但是只有m条网线,每台电脑一次只能连接一根网线,输出多少时间可以完成复制!

分析:模拟一下就好了! 下面给出AC代码:

代码语言:javascript
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 inline int read()
 5 {
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<'0'||ch>'9')
 9     {
10         if(ch=='-')
11             f=-1;
12         ch=getchar();
13     }
14     while(ch>='0'&&ch<='9')
15     {
16         x=x*10+ch-'0';
17         ch=getchar();
18     }
19     return x*f;
20 }
21 inline void write(int x)
22 {
23     if(x<0)
24     {
25         putchar('-');
26         x=-x;
27     }
28     if(x>9)
29     {
30         write(x/10);
31     }
32     putchar(x%10+'0');
33 }
34 inline ll gcd(ll x,ll p,ll mod)
35 {
36     ll cnt=1;
37     for(;p;p>>=1,x=x*x%mod)
38     {
39         if(p&1)
40             cnt=cnt*x%mod;
41     }
42     return cnt;
43 }
44 ll n,m;
45 int main()
46 {
47     int t;
48     t=read();
49     while(t--)
50     {
51         ll ans=0;
52         n=read();
53         m=read();
54         ll tim=1;
55         while(1)
56         {
57             if(tim>=m)
58             {
59                 tim=m;
60                 ans+=(n/tim);
61                 if(n%tim)
62                    ans++;
63                 break;
64             }
65             ans++;
66             n-=tim;
67             tim=tim*2;
68             if(n<=0)
69                break;
70         }
71         cout<<ans<<endl;
72     }
73     return 0;
74 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-07-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • B. New Job
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档