#include <bits/stdc++.h>
using namespace std;
const int N = 211111;
const long long base = 33ll;
int w, m, a[102];
int main() {
  cin >> w >> m;
  for (int i = 0; i < 101; ++i) {
    a[i] = m % w;
    m /= w;
  }
  for (int i = 0; i < 101; ++i) {
    a[i + 1] += a[i] / w;
    a[i] %= w;
    if (a[i] < 2) continue;
    if (a[i] + 1 == w) {
      ++a[i + 1];
      continue;
    }
    return puts("NO"), 0;
  }
  puts("YES");
}
