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.

题意就是复印文件,电缆有限,然后就是在电缆数允许的情况下1台电脑复印之后就有2台电脑可以继续进行复印,然后就是4台。。。达到电缆数所允许的最大值的时候剩下的就是按电缆数进行复印。

ヾ(。`Д´。),写这个题的时候智商不在家,wa了好几次。

代码:

 1 #include<bits/stdc++.h>
2 using namespace std;
3 int main(){
4 int t,n,m,i,cnt,ans;
5 scanf("%d",&t);
6 while(t--){
7 scanf("%d%d",&n,&m);
8 cnt=1;
9 for(i=0;n>0;i++){
10 if(cnt>m)n-=m;
11 else{
12 n-=cnt;
13 cnt*=2;
14 }
15 }
16 printf("%d\n",i);
17 }
18 return 0;
19 }

Codeforces Gym100952 B. New Job (2015 HIAST Collegiate Programming Contest)的更多相关文章

  1. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  2. Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】

    F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...

  3. Codeforces Gym100952 A.Who is the winner? (2015 HIAST Collegiate Programming Contest)

      A. Who is the winner?   time limit per test 1 second memory limit per test 64 megabytes input stan ...

  4. Codeforces Gym100952 D. Time to go back-杨辉三角处理组合数 (2015 HIAST Collegiate Programming Contest)

    D. Time to go back   time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Gym100952 C. Palindrome Again !!-回文字符串 (2015 HIAST Collegiate Programming Contest)

      C. Palindrome Again !!   time limit per test 1 second memory limit per test 64 megabytes input sta ...

  6. Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】

    J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...

  7. Gym 100952I&&2015 HIAST Collegiate Programming Contest I. Mancala【模拟】

    I. Mancala time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ou ...

  8. Gym 100952H&&2015 HIAST Collegiate Programming Contest H. Special Palindrome【dp预处理+矩阵快速幂/打表解法】

    H. Special Palindrome time limit per test:1 second memory limit per test:64 megabytes input:standard ...

  9. Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】

    G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...

随机推荐

  1. android 文件保存

    将数据保存在外部存储器上 /* Checks if external storage is available for read and write */ public boolean isExter ...

  2. 手动实现一个lazyMan

    这应该算一个经典的面试题了,就是一个关于流程控制的问题,要求如下 //实现一个LazyMan,可以按照以下方式调用: LazyMan("Hank")//输出: //Hi! This ...

  3. python 学习分享-线程

    多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长时间的程序中的任务放到后台去处理. 用户界面可以更加吸引人,这样比如用户点击了一个按钮去触发某些事件的处理,可以弹出一个进 ...

  4. NOIP2018 集训(二)

    A题 神炎皇 问题描述 神炎皇乌利亚很喜欢数对,他想找到神奇的数对. 对于一个整数对 \((a,b)\) ,若满足 \(a+b\leq n\) 且 \(a+b\) 是 \(ab\) 的因子,则称 为神 ...

  5. leetcode 211. 添加与搜索单词 - 数据结构设计 解题报告

    设计一个支持以下两种操作的数据结构: void addWord(word) bool search(word) search(word) 可以搜索文字或正则表达式字符串,字符串只包含字母 . 或 a- ...

  6. 初识MVC框架

    MVC框架 是一个框架模式,它使应用程序的输入.处理和输出分开.它可以使业务逻辑.数据.界面显示分离,使得耦合度大大降低,在这一方面与"三层"思想类似.      M--Model ...

  7. foreach的理解

    foreach的两种写法的解读 一.常见 1.理解:将数组元素逐个赋值给变量V,然后将v输出 2.代码: $arr = array(1,2,3,4,5); foreach($arr as $a){ e ...

  8. deeplearning4j——卷积神经网络对验证码进行识别

    一.前言 计算机视觉长久以来没有大的突破,卷积神经网络的出现,给这一领域带来了突破,本篇博客,将通过具体的实例来看看卷积神经网络在图像识别上的应用. 导读 1.问题描述 2.解决问题的思路 3.用DL ...

  9. POJ 1375 Intervals | 解析几何

    参考了这个博客 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath&g ...

  10. Educational Codeforces Round 22 E. Army Creation

    Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...