#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int w, m;
  cin >> w >> m;
  vector<long long int> bits(32), carry(32);
  long long int x = m, idx = 0;
  while (x) {
    long long int b = x % w;
    b += carry[idx];
    if (b == w) {
      carry[idx + 1]++;
    }
    b %= w;
    if (b == w - 1) {
      carry[idx + 1]++;
      b = 0;
    } else if (b > 1) {
      cout << "NO\n";
      return 0;
    }
    bits[idx] = b;
    idx++;
    x /= w;
  }
  cout << "YES\n";
  return 0;
}
