#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  if ((b + 1) % a != 0 && (b - 1) % a != 0 && b % a != 0) {
    cout << "NO";
    return 0;
  }
  long long c[1001] = {0};
  long long i = 0;
  while (b / a != 0) {
    c[i++] = b % a;
    b /= a;
  }
  c[i++] = b;
  for (long long k = 0; k < i; k++) {
    if (c[k] > 1 && c[k] < a - 1) {
      cout << "NO";
      return 0;
    }
    if (c[k] == a) {
      c[k + 1]++;
      c[k] = 0;
    }
    if (c[k] == a - 1) {
      c[k] = 0;
      c[k + 1]++;
      if (k == i) i++;
    }
  }
  cout << "YES";
  return 0;
}
