#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }
long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
long long fac(int n) {
  if (n == 1) return 1;
  return n * fac(n - 1);
}
int intlog(int base, double x) { return int(log(x) / log(base)); }
map<long long, bool> check;
int main() {
  long long w, m, x;
  cin >> w >> m;
  x = m;
  vector<long long> v;
  for (int i = 0; i <= 60; i++) {
    if (pow(w, i) >= 1e17) break;
    v.push_back(pow(w, i));
  }
  while (true) {
    if (x == 0) break;
    long long ss = -1;
    for (auto s : v) {
      if (abs(s - x) < x && !check[s]) {
        ss = s;
      }
    }
    if (ss == -1) break;
    check[ss] = true;
    x = abs(x - ss);
  }
  if (!x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
