题目
题目
代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n,a,b;
cin>>n>>a>>b;
bool flag=0;
if(a==1){
if(n%b==1%b) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
continue;
}
int suma=1;
for(int i=1;i<=30;i++){
if(suma>n){
break;
}
else{
if((n-suma)%b==0){
flag=1;
break;
}
}
suma*=a;
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}