#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, w, a, b, t, c;
  scanf("%I64d%I64d", &w, &n);
  t = 1;
  a = n;
  b = n;
  if (w <= 3) {
    printf("YES\n");
    return 0;
  }
  while (n > 0) {
    if (n % w == 0)
      ;
    else if (n % w == w - 1)
      a += t;
    else if (n % w == 1)
      a -= t;
    else {
      printf("NO\n");
      return 0;
    }
    n = round((double)n / (double)w);
    if (t > b)
      break;
    else
      t = t * w;
  }
  if (a == 0)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
