fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve(){
  5. long long a ,b ;
  6. cin>>a>>b;
  7.  
  8. int op = 0;
  9. int minops = INT_MAX;
  10.  
  11. // for the worst case scenario 10^9 and 1 we will need 30 max oprations log2(10^9) = 30
  12. // dividing takes O(logn) time;
  13.  
  14. // so what we will do is that we will iterate b for 30 times and will try to find combination of
  15. //type 1 and type 2 oprations so that it will take min
  16.  
  17.  
  18. for(int i =0; i < 30 ; i++){
  19. long long tempa = a;
  20. long long tempb = b+i;
  21.  
  22. if(tempb == 1) continue;
  23.  
  24. int op = i;
  25. while(tempa>0){
  26. tempa=tempa/tempb;
  27. op++;
  28. }
  29. minops = min(minops , op);
  30. }
  31.  
  32. cout<<minops<<endl;
  33.  
  34. // while(a>0){
  35. // b++;
  36. // a=a/b;
  37. // op++;
  38.  
  39. // minops = min(minops , op);
  40. // }
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47. int main() {
  48. int t;
  49. cin>>t;
  50. while(t--){
  51. solve();
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5316KB
stdin
6
9 2
1337 1
1 1
50000000 4
991026972 997
1234 5678
stdout
4
9
2
12
3
1