lina_os

Untitled

Dec 2nd, 2024 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  11.  
  12. int t;
  13. cin >> t;
  14. while (t--) {
  15. long long n, k;
  16. cin >> n >> k;
  17. if (n==1) {
  18. cout << 0 << endl;
  19. }
  20. else if (k==1) {
  21. cout << n-1 << endl;
  22. }
  23. else {
  24. long long i=1;
  25. long long hours=0;
  26. n--;
  27. while (n>0) {
  28. n-=i;
  29. hours++;
  30. if(i<k){
  31. if (i*2>k) {
  32. i=k;
  33. hours+=ceil(double(n)/double(i));
  34. break;
  35. }
  36. else i*=2;
  37. }
  38. }
  39. cout << hours << endl;
  40. }
  41. }
  42.  
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment