#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void P(int x) { cout << x << '\n'; }
void PP(int a, int b) { cout << a << " " << b << '\n'; }
void PV(vector<int> v) {
  int n = (v).size();
  for (auto& i : (v)) cout << i << " ";
  cout << '\n';
}
void PPV(vector<pair<int, int> > v) {
  int n = (v).size();
  for (auto& i : (v)) cout << i.first << " " << i.second << '\n';
}
const long long INF = (1LL << 60);
const int MOD = 1e9 + 7;
const int nax = 2e5 + 5;
const double p = 3.14159265359;
bool area(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  double A = a.first * (b.second - c.second) + b.first * (c.second - a.second) +
             c.first * (a.second - b.second);
  return ((A / 2) != 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int w, m;
  cin >> w >> m;
  while (m > 0) {
    int r = m % w;
    if (r <= 1) {
      m /= w;
    } else if (r == w - 1) {
      m = m / w + 1;
    } else {
      cout << ("NO") << '\n';
      exit(0);
    }
  }
  cout << ("YES") << '\n';
  return 0;
}
