#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a < b) return b;
  return a;
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
bool rec2(long long w, long long m);
bool rec1(long long w, long long m) {
  if (w <= 3 || m == 1 || rec2(w, m - 1) || rec2(w, m + 1) || rec2(w, m))
    return true;
  return false;
}
bool rec2(long long w, long long m) { return (m % w == 0 && rec1(w, m / w)); }
void solve() {
  long long w, m;
  cin >> w >> m;
  if (rec1(w, m))
    cout << "YES";
  else
    cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
