#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, k, l, j, m, n, rem, quo, w, flag = 0;
  cin >> w >> m;
  quo = m;
  while (quo != 0) {
    rem = quo % w;
    quo = quo / w;
    if ((rem != 0) && (rem != 1)) {
      if ((rem - w) == -1) {
        rem = -1;
        quo = quo + 1;
      } else {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 1)
    cout << "NO\n";
  else
    cout << "YES\n";
  return 0;
}
