#include <bits/stdc++.h>
using namespace std;
long long int p[101];
bool func(long long int l, long long int m) {
  if (l == 0)
    return m == 0;
  else if (p[l - 1] <= m)
    return func(l - 1, m - p[l - 1]);
  else
    return func(l - 1, p[l - 1] - m) || func(l - 1, m);
}
int main() {
  int w, m, i, last = 0;
  cin >> w >> m;
  p[0] = 1;
  for (i = 1; p[i - 1] <= 10000000000; i++) {
    p[i] = p[i - 1] * w;
    last++;
  }
  puts(func(last, m) ? "YES" : "NO");
  return 0;
}
