#include <bits/stdc++.h>
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  while (m) {
    if (m % w == 1) m--;
    if (m % w == w - 1) m++;
    if (m % w == 0)
      m /= w;
    else
      return puts("NO"), 0;
  }
  puts("YES");
}
