题目链接:http://codeforces.com/problemset/problem/165/B点击打开链接
因为没算一个数是否达到的复杂度是log级别的
因此可以用二分再降一个log
#include <bits/stdc++.h>
using namespace std;
int cal(int v,int k)
{
int sum=0;
while(v)
{
sum+=v;
v=v/k;
}
return sum;
}
int main()
{
int n,k;
cin >>n >>k;
int mid=n;
int ans=0;
int l=0;
int r=1e9;
while(l<=r)
{
int mid=(l+r)>>1;
if(cal(mid,k)>=n)
{
ans=mid;
r=mid-1;
}
else
l=mid+1;
}
cout <<ans <<endl;
}