样例输入
4
1 4 7
2 5 8
3 6 8
12 11 81
样例输出
No
Yes
No
No
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool rnk(ll a, ll b, ll n)
{
if((n-1) % b == 0) return true;
else if (a == 1) return false;
ll res = 1;
while(res < n)
{
res *= a;
if (res > n) break;
else if (res == n) return true;
else if ((n-res) % b == 0) return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t; cin >> t;
while(t--)
{
ll a, b, n;
cin >> a >> b >> n;
string ans = rnk(a,b,n)?"Yes":"No";
cout << ans <<'\n';
}
return 0;
}