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