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