CF1542B. Plus and Multiply
思路
题目就是问能不能找到一个\(x\)使得\(a^x+yb == n\)自己暴力枚举\(x\)即可
ac代码
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 inf = 1e18;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;
void solve() {
i64 a, b, n;
cin >> n >> a >> b;
if (a == 1) {
if ((n - 1) % b == 0) cout << "Yes\n";
else cout << "No\n";
return;
}
if (b == 1) {
cout << "Yes\n";
return;
}
for (int i = 0; ; i ++) {
i64 t = pow(a, i);
if (t > n) break;
if ((n - t) % b == 0) {
cout << "Yes\n";
return;
}
}
cout << "No\n";
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t --) solve();
return 0;
}