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