#include <bits/stdc++.h>
using namespace std;
int v[1000];
int main() {
  long long w, m;
  cin >> w >> m;
  int powMax = 0;
  long long n = m;
  long long pow = 1;
  while (n >= pow) {
    ++powMax;
    pow *= w;
  }
  pow /= w;
  int k = 0;
  while (n) {
    v[k++] = n / pow;
    n %= pow;
    pow /= w;
  }
  bool ok = true;
  for (int j = k - 1; j >= 0; --j) {
    if (v[j] > 1) {
      v[j] -= w;
      v[j - 1] += 1;
    }
    if (v[j] != -1 && v[j] != 0 && v[j] != 1) ok = false;
  }
  if (ok == true)
    cout << "YES";
  else
    cout << "NO";
}
