84pts萌新求助
查看原帖
84pts萌新求助
557961
Ephemeron楼主2023/12/30 11:14

RT

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
const int N = 1e3 + 9;
const int mod = 1e9;
ull l, r, k, flag, sum = 1;
int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	cin >> l >> r >> k;
	if (r == 1) { cout << 1; return 0; }
	if (k == 1) {
        if (l == 1 && r >= 1) { return 0; }
        else cout << -1;
	}
	for (int i = 0; i < 63; i++) {
		if (l <= sum && sum <= r) { flag = 1; cout << sum << " "; }
		if (sum >= 1e18 / k) break;
		sum *= k;
	}
	if (!flag) cout << -1;
	return 0;
}
2023/12/30 11:14
加载中...