#include <bits/stdc++.h>
using namespace std;
long long arr[50];
int lim;
bool ans;
void dfs(int ii, long long ll, long long rr) {
  if (ii > lim) return;
  if (ans) return;
  if (ll == rr) {
    ans = 1;
    return;
  }
  dfs(ii + 1, ll + arr[ii], rr);
  dfs(ii + 1, ll, rr + arr[ii]);
  dfs(ii + 1, ll, rr);
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  map<long long, long long> mp;
  long long n, m;
  cin >> n >> m;
  if (n < 4) {
    cout << "YES\n";
    return 0;
  }
  arr[0] = 1;
  for (lim = 1;; lim++) {
    arr[lim] = arr[lim - 1] * n;
    if (arr[lim] > m * 4) break;
  }
  dfs(0, 0, m);
  if (ans)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
