#include <bits/stdc++.h>
using namespace std;
int ans[1010] = {};
int main() {
  int w, m, i, j;
  scanf("%d%d", &w, &m);
  i = 0;
  while (m) {
    ans[++i] = m % w;
    m /= w;
  }
  int flag = 0;
  for (i = 1; i <= 1000; i++) {
    if (ans[i] == 0 || ans[i] == 1)
      continue;
    else if (ans[i] + 1 >= w) {
      ans[i + 1] += 1;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
