-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Add_and_Divide.cpp
More file actions
64 lines (56 loc) · 1.4 KB
/
A_Add_and_Divide.cpp
File metadata and controls
64 lines (56 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/******************************************************************************
A. Add and Divide
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have two positive integers a and b.
You can perform two kinds of operations:
a=⌊ab⌋ (replace a with the integer part of the division between a and b)
b=b+1 (increase b by 1)
Find the minimum number of operations required to make a=0.
Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The only line of the description of each test case contains two integers a, b (1≤a,b≤109).
Output
For each test case, print a single integer: the minimum number of operations required to make a=0.
*******************************************************************************/
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll a, ll b){
if(a==0){
cout<<0<<endl;
return;
}
else if(a<b){
cout<<1<<endl;
return;
}
int ans=INT_MAX;
int i=0;
if(b==1)i=1;
for(;i*i<=a;i++){
int x=0;
int c=a;
while(c>0){
c=c/(b+i);
x++;
}
ans=min(ans,x+i);
}
cout<<ans<<endl;
return ;
}
int main()
{
ll t;
cin>>t;
while(t--){
ll a,b;
cin>>a>>b;
solve(a,b);
}
return 0;
}