#include <bits/stdc++.h>
using namespace std;
long long int w, m;
long long int D(long long int x) {
  if (x < 0LL) return -x;
  return x;
}
long long int P(int a) {
  long long int ans = 1;
  while (a) {
    ans = ans * 2;
    a--;
  }
  return ans;
}
int main() {
  cin >> w >> m;
  long long int fe[110];
  long long int t = m;
  for (int i = 0; i < 100; i++) {
    fe[i] = (t % w);
    t = (t / w);
  }
  int f = 1;
  for (int i = 0; i < 99; i++) {
    if (fe[i] == w) {
      fe[i] = 0;
      fe[i + 1]++;
    }
    if (fe[i] <= 1LL) {
      fe[i] = 0;
      continue;
    }
    if (fe[i] == w - 1LL) {
      fe[i] = 0;
      fe[i + 1]++;
      continue;
    }
    f = 0;
    break;
  }
  printf("%s\n", f ? "YES" : "NO");
}
