参考https://blog.csdn.net/Yonggie/article/details/77471349
代码:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int c,k;
cin>>c>>k;
int xh=0;
int jz[105];
while(k)
{
jz[xh++]=k%c;
k/=c;
}
int flag=1;
for(int i=0;i<xh;i++)
{
if(jz[i]>=c)
{
jz[i+1]+=(jz[i]/c);
jz[i]%=c;
}
if(jz[i]==1||jz[i]==0)continue;
else if(jz[i]==c-1)
{
jz[i+1]++;
}
else
{
flag=0;
break;
}
}
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}