#include <bits/stdc++.h>
using namespace std;
long long Pow(long long x, int y) {
  long long sum = 1;
  for (int i = 1; i <= y; i++) {
    sum = sum * x;
  }
  return sum;
}
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  while (m != 1 && m != 0) {
    if (m % w != 1 && m % w != 0 && m % w != w - 1) {
      puts("NO");
      return 0;
    }
    if (m % w == w - 1) {
      m = m / w + 1;
    } else {
      m = m / w;
    }
  }
  puts("YES");
  return 0;
}
