#include <bits/stdc++.h>
using namespace std;
long long n, w;
bool check(long long x, long long cur, long long val) {
  if (val == n) return true;
  if (abs(val - n) < cur) return false;
  return (check(x + 1, cur * w, val) || check(x + 1, cur * w, val + cur) ||
          check(x + 1, cur * w, val - cur));
}
int main() {
  cin >> w >> n;
  if (w == 2 || w == 3 || check(0, 1, 0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
