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