题目链接:
Problem - 165B - Codeforceshttps://codeforces.com/problemset/problem/165/B
题目大意:
最后写了至少n个,每次衰减k倍(/k),问最初的v最小为多少。
思路&方法:
二分答案。
AC代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" ll n,k,l=0,r; bool found(ll x){ ll sum=0; while(x){ sum+=x; x/=k; } return sum >= n; } void solve(){ cin >> n >> k; r=n; while(l < r){ ll mid = l+(r-l >> 1); found(mid) ? r = mid : l = mid +1; } cout << l << endl; return; } int main(){ ll t=1;//cin >> t; while(t--)solve(); return 0; }