WA on #7
查看原帖
WA on #7
637788
kimi0705楼主2023/3/7 22:04
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
bool check(int x) {
	int sum = 0;
	while(x) {
		sum += x;
		x /= m;
	}
	if(sum >= n) return true;
	else return false;
}
int binary_search() {
	int l = 1, r = n, ans = 1;
	while(l < r) {
		int mid = (l + r) / 2;
		if(check(mid)) {
			ans = mid;
			r = mid - 1;
		}else {
			l = mid + 1;
		}
	}
	return ans;
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	cout << binary_search() << endl;
	return 0;
}
2023/3/7 22:04
加载中...