URAL 1131. Copying (math)

来源:互联网 发布:oracle数据库外键约束 编辑:程序博客网 时间:2024/05/28 15:08

1131. Copying

Time limit: 0.25 second
Memory limit: 64 MB
A new educating program was received by the kindergarten. Of course, children have discovered it immediately and want to play with it as soon as possible. In order to let them do it the program has to be copied to all theN computers that the kindergarten had bought just before the default of 1998. At the moment the program is installed only on one computer. Other computers do not have floppy drives and are not connected with a local network. The only way to transfer information from one computerto another is to copy it using a null-modem cable (a cable that connects two computers directly). So, if the program is installed on a computer, it can be copied to some other (but only one!) computer within an hour. There are only K null-modem cables in the kindergarten. Your task is to estimate the minimal time necessary for copying the program to all the computers in the kindergarten.

Input

The only input line contains two integers separated with a space:Nand K (1 ≤ N ≤ 109; 1 ≤ K ≤ 109).

Output

You are to output the minimal time (in hours) necessary for copying of the program to all the computers.

Sample

inputoutput
8 3
4
Problem Author: Stanislav Vasilyev, Alexander Mironenko
Problem Source: VI Ural State University Collegiate Programming Contest (21.10.2001)




解析:每个接口两端只能连两台电脑,这就代表了一台电脑只能同时为一台电脑传送数据。并且每小时一台电脑。直接模拟计算即可。




AC代码:

#include <bits/stdc++.h>using namespace std;int main(){    int n, k, ans;    scanf("%d%d", &n, &k);    for(ans = 0; (1 << ans) < k && (1 << ans) < n; ans ++) ;    if((1 << ans) < n)        ans += (n - (1 << ans) - 1) / k + 1;    printf("%d\n", ans);    return 0;}





0 0