#include <bits/stdc++.h>
using namespace std;
bool solve() {
  long long w, m;
  scanf("%lld %lld", &w, &m);
  long long t = 0;
  while (m > 0) {
    m += t;
    if (m % w != 0 && m % w != 1 && m % w != w - 1) {
      return false;
    }
    if (m % w == w - 1)
      t = 1;
    else
      t = 0;
    m /= w;
  }
  return true;
}
int main(void) { printf("%s\n", solve() ? "YES" : "NO"); }
