#include <bits/stdc++.h>
long long a, n, k, i;
int main() {
  scanf("%I64d %I64d", &a, &n);
  k = 1;
  if (a <= 3) {
    printf("YES\n");
    return 0;
  }
  for (i = 0; i <= 100; i++) {
    if (n % a == 1)
      n--;
    else if (n % a == a - 1)
      n++;
    else if (n % a == 0)
      ;
    else {
      printf("NO\n");
      return 0;
    }
    n /= a;
  }
  if (n == 0) printf("YES\n");
}
