import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;
public class TaskD {
private final InputReader reader;
private final OutputWriter writer;
public TaskD(InputReader reader, OutputWriter writer) {
this.reader = reader;
this.writer = writer;
}
public static void main
(String[] args
) { InputReader reader
= new InputReader
(System.
in); OutputWriter writer
= new OutputWriter
(System.
out); new TaskD(reader, writer).run();
writer.writer.flush();
}
public void run() {
int w = reader.nextInt(), m = reader.nextInt();
if (w <= 3)
writer.printf("YES\n");
else {
while (m != 0) {
if (m % w != (w - 1) && m % w != 0 && m % w != 1) {
writer.printf("NO\n");
return;
}
m = (m + 1) / w;
}
writer.printf("YES\n");
}
}
static class InputReader {
tokenizer = null;
}
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
}
}
return tokenizer.nextToken();
}
public int nextInt() {
}
public double nextDouble() {
return Double.
parseDouble(next
()); }
public long nextLong() {
return Long.
parseLong(next
()); }
}
static class OutputWriter {
}
}
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC5Mb2NhbGU7CmltcG9ydCBqYXZhLnV0aWwuU3RyaW5nVG9rZW5pemVyOwoKcHVibGljIGNsYXNzIFRhc2tEIHsKICAgIHByaXZhdGUgZmluYWwgSW5wdXRSZWFkZXIgcmVhZGVyOwogICAgcHJpdmF0ZSBmaW5hbCBPdXRwdXRXcml0ZXIgd3JpdGVyOwoKICAgIHB1YmxpYyBUYXNrRChJbnB1dFJlYWRlciByZWFkZXIsIE91dHB1dFdyaXRlciB3cml0ZXIpIHsKICAgICAgICB0aGlzLnJlYWRlciA9IHJlYWRlcjsKICAgICAgICB0aGlzLndyaXRlciA9IHdyaXRlcjsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgSW5wdXRSZWFkZXIgcmVhZGVyID0gbmV3IElucHV0UmVhZGVyKFN5c3RlbS5pbik7CiAgICAgICAgT3V0cHV0V3JpdGVyIHdyaXRlciA9IG5ldyBPdXRwdXRXcml0ZXIoU3lzdGVtLm91dCk7CiAgICAgICAgbmV3IFRhc2tEKHJlYWRlciwgd3JpdGVyKS5ydW4oKTsKICAgICAgICB3cml0ZXIud3JpdGVyLmZsdXNoKCk7CiAgICB9CgogICAgcHVibGljIHZvaWQgcnVuKCkgewogICAgICAgIGludCB3ID0gcmVhZGVyLm5leHRJbnQoKSwgbSA9IHJlYWRlci5uZXh0SW50KCk7CiAgICAgICAgaWYgKHcgPD0gMykKICAgICAgICAgICAgd3JpdGVyLnByaW50ZigiWUVTXG4iKTsKICAgICAgICBlbHNlIHsKICAgICAgICAgICAgd2hpbGUgKG0gIT0gMCkgewogICAgICAgICAgICAgICAgaWYgKG0gJSB3ICE9ICh3IC0gMSkgJiYgbSAlIHcgIT0gMCAmJiBtICUgdyAhPSAxKSB7CiAgICAgICAgICAgICAgICAgICAgd3JpdGVyLnByaW50ZigiTk9cbiIpOwogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG0gPSAobSArIDEpIC8gdzsKICAgICAgICAgICAgfQogICAgICAgICAgICB3cml0ZXIucHJpbnRmKCJZRVNcbiIpOwogICAgICAgIH0KICAgIH0KCgogICAgc3RhdGljIGNsYXNzIElucHV0UmVhZGVyIHsKICAgICAgICBwdWJsaWMgQnVmZmVyZWRSZWFkZXIgcmVhZGVyOwogICAgICAgIHB1YmxpYyBTdHJpbmdUb2tlbml6ZXIgdG9rZW5pemVyOwoKICAgICAgICBwdWJsaWMgSW5wdXRSZWFkZXIoSW5wdXRTdHJlYW0gc3RyZWFtKSB7CiAgICAgICAgICAgIHJlYWRlciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIoc3RyZWFtKSwgMzI3NjgpOwogICAgICAgICAgICB0b2tlbml6ZXIgPSBudWxsOwogICAgICAgIH0KCiAgICAgICAgcHVibGljIFN0cmluZyBuZXh0KCkgewogICAgICAgICAgICB3aGlsZSAodG9rZW5pemVyID09IG51bGwgfHwgIXRva2VuaXplci5oYXNNb3JlVG9rZW5zKCkpIHsKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgdG9rZW5pemVyID0gbmV3IFN0cmluZ1Rva2VuaXplcihyZWFkZXIucmVhZExpbmUoKSk7CiAgICAgICAgICAgICAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBlKSB7CiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IFJ1bnRpbWVFeGNlcHRpb24oZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHRva2VuaXplci5uZXh0VG9rZW4oKTsKICAgICAgICB9CgogICAgICAgIHB1YmxpYyBpbnQgbmV4dEludCgpIHsKICAgICAgICAgICAgcmV0dXJuIEludGVnZXIucGFyc2VJbnQobmV4dCgpKTsKICAgICAgICB9CgogICAgICAgIHB1YmxpYyBkb3VibGUgbmV4dERvdWJsZSgpIHsKICAgICAgICAgICAgcmV0dXJuIERvdWJsZS5wYXJzZURvdWJsZShuZXh0KCkpOwogICAgICAgIH0KCiAgICAgICAgcHVibGljIGxvbmcgbmV4dExvbmcoKSB7CiAgICAgICAgICAgIHJldHVybiBMb25nLnBhcnNlTG9uZyhuZXh0KCkpOwogICAgICAgIH0KICAgIH0KCiAgICBzdGF0aWMgY2xhc3MgT3V0cHV0V3JpdGVyIHsKICAgICAgICBwdWJsaWMgUHJpbnRXcml0ZXIgd3JpdGVyOwoKICAgICAgICBPdXRwdXRXcml0ZXIoT3V0cHV0U3RyZWFtIHN0cmVhbSkgewogICAgICAgICAgICB3cml0ZXIgPSBuZXcgUHJpbnRXcml0ZXIoc3RyZWFtKTsKICAgICAgICB9CgogICAgICAgIHB1YmxpYyB2b2lkIHByaW50ZihTdHJpbmcgZm9ybWF0LCBPYmplY3QuLi4gYXJncykgewogICAgICAgICAgICB3cml0ZXIucHJpbnQoU3RyaW5nLmZvcm1hdChMb2NhbGUuRU5HTElTSCwgZm9ybWF0LCBhcmdzKSk7CiAgICAgICAgfQogICAgfQp9Cgo=