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