您的位置:首页 > 其它

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

2017-07-24 07:24 681 查看

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
inline ll gcd(ll x,ll p,ll mod)
{
ll cnt=1;
for(;p;p>>=1,x=x*x%mod)
{
if(p&1)
cnt=cnt*x%mod;
}
return cnt;
}
ll n,m;
int main()
{
int t;
t=read();
while(t--)
{
ll ans=0;
n=read();
m=read();
ll tim=1;
while(1)
{
if(tim>=m)
{
tim=m;
ans+=(n/tim);
if(n%tim)
ans++;
break;
}
ans++;
n-=tim;
tim=tim*2;
if(n<=0)
break;
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐