#include <bits/stdc++.h>
using namespace std;
bool solve(int w, int m);
bool trysolve(int w, int m) {
  if (m % w != 0) return false;
  return solve(w, m / w);
}
bool solve(int w, int m) {
  if (w == 2 || w == 3 || m == 1) return true;
  return trysolve(w, m + 1) || trysolve(w, m) || trysolve(w, m - 1);
}
int main() {
  int w, m;
  cin >> w >> m;
  bool f = solve(w, m);
  if (f)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
