#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1000000007;
const long long FMOD = 998244353;
const long double eps = 1e-9;
long long w, m;
const long long inf = 2e9;
void solve(long long x, long long y) {
  if (x == m) {
    cout << "YES";
    exit(0);
  }
  if (y > inf) return;
  solve(x + y, y * w);
  solve(x - y, y * w);
  solve(x, y * w);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> w >> m;
  if (w <= 3) {
    cout << "YES";
    return 0;
  }
  solve(0, 1);
  cout << "NO";
}
