#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int w, m;
bool make(long long int n) {
  if (n == 1 || n == 0) return true;
  bool possible = false;
  if ((n + 1) % w == 0)
    if (make((n + 1) / w)) possible = true;
  if ((n - 1) % w == 0)
    if (make((n - 1) / w)) possible = true;
  if (n % w == 0)
    if (make(n / w)) possible = true;
  return possible;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> w >> m;
  if (make(m))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
