#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dr4[] = {0, 1, -1, 0};
int dc4[] = {1, 0, 0, -1};
bool solve(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);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int w, m;
  cin >> w >> m;
  map<int, string> mm;
  mm[1] = "YES";
  mm[0] = "NO";
  cout << mm[solve(w, m)];
}
