思路:二分法,v最小是1,最大是n,不断二分看是否能达到n
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#define ll long long
#define max_ 50
using namespace std;
ll n,k;
bool judge(ll x)
{
ll sum=x,p=k;
while(x/p!=0)
{
sum+=x/p;
p=p*k;
}
if(sum>=n)
return true;
else
return false;
}
int main(int argc, char const *argv[]) {
scanf("%lld%lld",&n,&k);
ll l=1,r=n,ans;
while(l<=r)
{
ll mid=(l+r)>>1;
if(judge(mid))
{
ans=mid;
r=mid-1;
}
else
l=mid+1;
}
printf("%lld\n",ans );
return 0;
}