#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  while (m) {
    if (m % w == 0 || m % w == 1)
      m = m / w;
    else if (m % w == w - 1)
      m = (m + 1) / w;
    else {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}
