#include <bits/stdc++.h>
using namespace std;
bool solve(long long int w, long long int m, long long int cnt);
bool solve2(long long int w, long long int m, long long int cnt) {
  return ((m % w == 0) && solve(w, m / w, cnt + 1));
}
bool solve(long long int w, long long int m, long long int cnt) {
  if (cnt > 100) return 0;
  return m == 1 || solve2(w, m, cnt) || solve2(w, m - 1, cnt) ||
         solve2(w, m + 1, cnt);
}
int main() {
  long long int w, m, i, j, k;
  cin >> w >> m;
  bool ans = solve(w, m, 0);
  if (ans == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
