[Description]
In this question, the given Code task is n lines, and the starting code writing capability is V Lines. Then, each time the Code is divided by K, when v becomes 0, check whether the code task N is completed? And find the smallest v.
[Solution ideas]
We can divide the V value into two parts and then determine the final V value.
AC code]
1 #include<iostream> 2 using namespace std; 3 int ok(int v,int k) 4 { 5 int sum=v; 6 while(v!=0) 7 { 8 sum+=v/k; 9 v/=k;10 }11 return sum;12 }13 int main()14 {15 int n,k;16 while(cin>>n>>k)17 {18 int up,low,ans=1;19 if(n>k)20 {21 up=n;low=1;22 while(low<=up) 23 {24 int mid=(up+low)/2;25 int num=ok(mid,k);26 if(num>=n) {up=mid-1;ans=mid;}27 else low=mid+1; 28 } 29 }30 else 31 {32 up=k;low=1;33 while(low<=up) 34 {35 int mid=(up+low)/2;36 int num=ok(mid,k);37 if(num>=n) {up=mid-1;ans=mid;}38 else low=mid+1; 39 } 40 }41 42 cout<<ans<<endl;43 }44 return 0;45 }