-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurning Midnight Oil.cpp
More file actions
48 lines (46 loc) · 926 Bytes
/
Copy pathBurning Midnight Oil.cpp
File metadata and controls
48 lines (46 loc) · 926 Bytes
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <iomanip>
#include <cstring>
using namespace std;
int val(int beg, int en, int k, int sum){
int s=0;
int w=1;
if(beg==en)
return beg;
else{
int mid = (beg+en)/2;
for(int i=0; w>0 && s<sum; i++){
w=mid/pow(k,i);
s+=w;
}
if(s>=sum){
return val(beg, mid, k, sum);
}
else{
if(mid==beg)
return en;
else
return val(mid, en, k, sum);
}
}
}
void init() {
cin.tie(0);
cin.sync_with_stdio(0);
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
init();
long long n,k;
cin >> n;
cin >> k;
int i = val(0, n, k, n);
cout << i;
return 0;
}