#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
void work() {
  cin >> n >> m;
  while (m) {
    int x = m % n;
    if (x <= 1) {
      m /= n;
    } else {
      if (x + 1 != n) {
        puts("NO");
        return;
      }
      m /= n;
      ++m;
    }
  }
  puts("YES");
}
int main() {
  work();
  return 0;
}
