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