a0,a1…an=0,-1,1
m = a0 * n^0 + a1 * n^1 + a2 * n^2 + ………… + a100 * n^100
m每次取余n 那么m%n=a0
然后(m-a0)/n 得出m1=a1+a2n+…+a100n99以此类推得出a1
依次类推得出a100
#include <bits/stdc++.h>
#define ll long long
#define INF 0x7f7f7f7f
using namespace std;
typedef pair<int,string> PII;
const int N=1e5+10;
int n,m,ans;
bool check(){
while(m){
int r=m%n;
if(r!=1&&r!=0&&r!=n-1)return false;//r!=n-1等价于r!=-1
//eg 4%5=5-1余数可以为-1,但是数学上余数为4,两个正数取余一定为正数,所以要规避-1
if(r>1)r=-1;
m-=r;
m/=n;
}
return true;
}
int main() {
cin>>n>>m;
if(check())cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}