#include <bits/stdc++.h>
using namespace std;
int w, m, size;
long long v[20];
bool can(long long x = 0, int n = 0) {
  if (x == m) return 1;
  if (n == size) return 0;
  if (can(x + v[n], n + 1)) return 1;
  if (can(x - v[n], n + 1)) return 1;
  if (can(x, n + 1)) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &w, &m);
  if (w <= 3) {
    puts("YES");
    return 0;
  }
  long long power = 1;
  long long prev = 0;
  size = 0;
  while (power - prev <= m) {
    prev += power;
    v[size++] = power, power *= w;
  }
  puts(can() ? "YES" : "NO");
  return 0;
}
