#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
bool solve(int, int);
bool trySolve(int, int);
bool trySolve(int w, int m) { return (m % w == 0 && solve(w, m / w)); }
bool solve(int w, int m) {
  return (w <= 3 || m == 1 || trySolve(w, m - 1) || trySolve(w, m) ||
          trySolve(w, m + 1));
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int w, m;
  cin >> w >> m;
  if (w == 2 || w == 3)
    cout << "YES";
  else {
    if (solve(w, m))
      cout << "YES";
    else
      cout << "NO";
  }
  return 0;
}
