#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long w, m;
  cin >> w >> m;
  while (m) {
    if (m % w < 2)
      m /= w;
    else if (m % w == w - 1)
      m = (m + w) / w;
    else {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}
