Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t;
- cin >> t;
- while (t--) {
- long long n, k;
- cin >> n >> k;
- if (n==1) {
- cout << 0 << endl;
- }
- else if (k==1) {
- cout << n-1 << endl;
- }
- else {
- long long i=1;
- long long hours=0;
- n--;
- while (n>0) {
- n-=i;
- hours++;
- if(i<k){
- if (i*2>k) {
- i=k;
- hours+=ceil(double(n)/double(i));
- break;
- }
- else i*=2;
- }
- }
- cout << hours << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment