import java.util.* ;
import java.io.* ;
import java.math.* ;
class Main {
Scanner sc
= new Scanner
( System .
in ) ; //new File("input.txt")); int w = sc.nextInt ( ) , m = sc.nextInt ( ) ;
int flag = 1 ;
int a[ ] = new int [ 40 ] ;
for ( int i = 0 ; i < 35 ; i++ )
a[ i] = 0 ;
int sz = 0 ;
while ( m > 0 )
{
a[ sz++ ] = m% w;
m /= w;
}
for ( int i = 0 ; i <= sz; i++ )
if ( a[ i] != 0 && a[ i] != 1 && a[ i] != w- 1 && a[ i] != w)
{
flag = 0 ;
break ;
}
else
{
if ( a[ i] == w- 1 || a[ i] == w)
a[ i+ 1 ] ++;
}
if ( flag == 1 )
pw.println ( "YES" ) ;
else
pw.println ( "NO" ) ;
pw.close ( ) ;
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5pby4qOwppbXBvcnQgamF2YS5tYXRoLio7CgpjbGFzcyBNYWluIHsKCQoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgdGhyb3dzIElPRXhjZXB0aW9uewoJCVNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOy8vbmV3IEZpbGUoImlucHV0LnR4dCIpKTsKCSAgICBQcmludFdyaXRlciBwdyA9IG5ldyBQcmludFdyaXRlcihTeXN0ZW0ub3V0KTsvL25ldyBGaWxlKCJvdXRwdXQudHh0IikpOwoJICAgIGludCB3ID0gc2MubmV4dEludCgpLCBtID0gc2MubmV4dEludCgpOwoJICAgIGludCBmbGFnID0gMTsKCSAgICBpbnQgYVtdID0gbmV3IGludFs0MF07CgkgICAgZm9yIChpbnQgaSA9IDA7IGkgPCAzNTsgaSsrKQoJICAgIAlhW2ldID0gMDsKCSAgICBpbnQgc3ogPSAwOwoJICAgIHdoaWxlIChtID4gMCkKCSAgICB7CgkgICAgCWFbc3orK10gPSBtJXc7CgkgICAgCW0gLz0gdzsKCSAgICB9CgkJZm9yIChpbnQgaSA9IDA7IGkgPD0gc3o7IGkrKykKCQkJaWYgKGFbaV0gIT0gMCAmJiBhW2ldICE9IDEgJiYgYVtpXSAhPSB3LTEgJiYgYVtpXSAhPSB3KQoJCQl7CgkJCSAgIGZsYWcgPSAwOwoJCQkgICBicmVhazsKCSAgICAgICAgfQoJICAgICAgICBlbHNlCgkgICAgICAgIHsKCQkJCWlmIChhW2ldID09IHctMSB8fCBhW2ldID09IHcpCgkJCQkgICBhW2krMV0rKzsKCSAgICAgICAgfQoJCWlmIChmbGFnID09IDEpCgkJICAgcHcucHJpbnRsbigiWUVTIik7CgkJZWxzZQoJCQlwdy5wcmludGxuKCJOTyIpOwoJICAgcHcuY2xvc2UoKTsKCX0KfQo=