#include <bits/stdc++.h>
using namespace std;
void rwFile() {
  freopen("INP.inp", "r", stdin);
  freopen("OUT.out", "w", stdout);
}
void solveC_VanyaAndScales() {
  long long w, m;
  cin >> w >> m;
  if (w == 2) {
    cout << "YES";
    return;
  }
  int able = 1;
  while (m) {
    long long tmp = m % w;
    m /= w;
    if (tmp == w - 1) {
      m++;
      continue;
    }
    if (tmp == 1 || tmp == 0) continue;
    able = 0;
    break;
  }
  if (able == 1)
    cout << "YES";
  else
    cout << "NO";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solveC_VanyaAndScales();
}
