#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m;
  while (~scanf("%d%d", &w, &m)) {
    int f = 1;
    while (m > 0) {
      int res = m % w;
      if (res != 0 && res != 1 && res == w - 1) {
        m++;
      } else if (res != 0 && res != 1) {
        f = 0;
        break;
      }
      m /= w;
    }
    if (f == 1)
      printf("YES\n");
    else
      printf("NO\n");
  }
}
