手模拟了一下
观察每个式子,化简得到:
// AC one more times
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define inf64 0x3f3f3f3f3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long,long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
void solve()
{
ll n, a, b;
cin>>n>>a>>b;
if(b == 1)
{
cout<<"YES"<<endl;
return;
}
if(a == 1)
{
if((n - 1) % b == 0)
{
cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
return;
}
bool ok = false;
for(ll i = 0; pow(a, i) <= n; i++)
{
ll t1 = pow(a, i);
if((n - t1) % b == 0)
ok = true;
}
if(ok)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return;
}
int main()
{
//std::ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
// 特殊输入 请注释上方,如__int128等
int TC = 1;
cin >> TC;
for(int tc = 1; tc <= TC; tc++)
{
//cout << "Case #" << tc << ": ";
solve();
}
return 0;
}
标签:typedef,int,long,Plus,Multiply,define
From: https://www.cnblogs.com/magicat/p/17301315.html