-
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 (62 loc) · 1.14 KB
/
A_Add_and_Divide.cpp
File metadata and controls
64 lines (62 loc) · 1.14 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
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define input for(int &i:v) cin >> i;
void print(const vector<int>& v) {
for (int i : v) {
cout << i << " ";
}
cout << endl;
}
void solve() {
int a,b;
cin >> a >> b;
if(a==b) {
cout << 2 << endl;
return;
}
if(b>a)
{
cout << 1 << endl;
return;
}
bool flag = false;
if(b==1) {
b++;
flag = true;
}
int ans = a-b+2; //make b = a+1, take a-b+1 operations then divide so one more op
int B=b, A;
while(true)
{
//find smallest power of b more than a
A = a;
int power=1;
while(A>=B)
{
A/=B;
power++;
}
int tempans = power + (B-b);
if(tempans > ans){
break;
}
else{
ans = tempans;
B++;
}
}
if(flag) ans++;
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t-- > 0) {
solve();
}
}