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