#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LLINF = numeric_limits<long long>::max();
const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();
int w;
bool solve(int m) {
  return (!m || (m % w == 0 && solve(m / w)) ||
          ((m - 1) % w == 0 && solve((m - 1) / w)) ||
          ((m + 1) % w == 0 && solve((m + 1) / w)));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int m;
  cin >> w >> m;
  cout << (solve(m) ? "YES" : "NO");
  return 0;
}
