#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll powp(int k, int l){//快速幂
	ll i, j, sum = 1;
	for(i = 1; i <= l; i++) {
		sum*=k;
	}
	return sum;
}
int cheak(int m, int k){//检查
	int i = 1, sum = m, p;
	p = m / k;
	while(p){
		sum+=p;
		i++;
		p = m/powp(k,i);
	}
	return sum;
}
int main() {
	int n, k;
	scanf("%d%d",&n,&k);
	int l = 1, r = n;
	int m = (l+r)/2;
	while(l < r){//二分查找
		if(cheak(m,k) < n){
			l = m+1;
		}else if(cheak(m,k) > n){
			r = m;
		}else {
			break;
		}
		m = (l+r)/2;
	}
	printf("%d\n",m);
	return 0;
}

根据题意的操作简单二分暴力过就可以了

有一个点没注意    就是a/b == 0  是指 a < b