#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, m;
  cin >> w >> m;
  while (true) {
    if (w <= 3 || m == 1) {
      cout << "YES";
      return 0;
    }
    if (m % w == 0) {
      m = m / w;
    } else if ((m - 1) % w == 0) {
      m = (m - 1) / w;
    } else if ((m + 1) % w == 0) {
      m = (m + 1) / w;
    } else {
      cout << "NO";
      return 0;
    }
  }
  return 0;
}
