#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, m;
  cin >> w >> m;
  long long cur = 1;
  while (cur < m) cur *= w;
  while (cur) {
    m = min(m, abs(m - cur));
    cur /= w;
  }
  if (m == 0)
    cout << "YES\n";
  else
    cout << "NO\n";
}
