#include <bits/stdc++.h>
using namespace std;
int solve();
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
const int N = 100 + 5;
void p(int t) {
  if (t == 1)
    puts("YES");
  else
    puts("NO");
  exit(0);
}
int solve() {
  long long w, m;
  cin >> w >> m;
  if (w == 2) {
    p(1);
  }
  vector<long long> pw;
  long long c = 1;
  while (c <= m) {
    pw.push_back(c);
    c *= w;
  }
  pw.push_back(c);
  c *= w;
  pw.push_back(c);
  c *= w;
  int m1 = (int)pw.size() / 2;
  int m2 = (int)pw.size() - m1;
  set<long long> w1;
  long long P1 = 1;
  for (int i = 0; i < m1; i++) P1 *= 3;
  for (int mask = 0; mask < P1; mask++) {
    long long l = 0;
    int k = mask;
    for (int j = 0; j < m1; j++) {
      int ost = k % 3;
      if (ost == 1)
        l += pw[j];
      else if (ost == 2)
        l -= pw[j];
      k /= 3;
    }
    w1.insert(l);
  }
  long long P2 = 1;
  for (int i = 0; i < m2; i++) P2 *= 3;
  for (int mask = 0; mask < P2; mask++) {
    long long r = 0;
    int k = mask;
    for (int j = 0; j < m2; j++) {
      int ost = k % 3;
      if (ost == 1)
        r += pw[j + m1];
      else if (ost == 2)
        r -= pw[j + m1];
      k /= 3;
    }
    long long x = r + m;
    if (w1.find(x) != w1.end()) p(1);
    long long y = r - m;
    if (w1.find(y) != w1.end()) p(1);
  }
  p(0);
  return 0;
}
