#include <bits/stdc++.h>
using namespace std;
int weigh(long long n, long long m, long long prev, long long prevprev) {
  long long x, y;
  x = 1;
  while (x <= m) x = x * n;
  y = x / n;
  if (x == prev && y == prevprev) return 0;
  if (x == prevprev && y == prev) return 0;
  if (y == m && prev != y) return 1;
  if (y == m && prev == y) return 0;
  int p = 0;
  if (x != prev) {
    p = p | weigh(n, x - m, x, prev);
  }
  if (y != prev) {
    p = p | weigh(n, m - y, y, prev);
  }
  return p;
}
int main() {
  long long n, m;
  cin >> n >> m;
  long long x, y;
  x = 1;
  while (x <= m) x = x * n;
  y = x / n;
  if (m == y) {
    printf("YES");
    return 0;
  }
  int p = weigh(n, x - m, x, 0);
  p = p | weigh(n, m - y, y, 0);
  if (p)
    printf("YES");
  else
    printf("NO");
  return 0;
}
