#include <bits/stdc++.h>
using namespace std;
long long a[1000010];
int main() {
  long long w, m;
  cin >> w >> m;
  long long tmp = w;
  while (tmp < m) tmp *= w;
  bool ok = 0;
  while (1) {
    if (tmp > m) {
      if (tmp - m < m) {
        m = tmp - m;
      }
    } else {
      m -= tmp;
    }
    if (m == 0) {
      ok = 1;
      break;
    }
    tmp /= w;
    if (tmp == 0) break;
  }
  if (ok) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
