题目链接: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;
}
lines, drinks another cup of tea, then he writes
lines and so on:
,
,
, ...
is regarded as the integral part from dividing number
equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.
947


&spm=1001.2101.3001.11974&articleId=79133153&d=1&t=3&u=2fdaec6bca1245a785446114fb262233)

被折叠的 条评论
为什么被折叠?



