#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > g;
long long dp[3003][3003], a[40], b[40];
long long flag = 0, c = 0;
void sol(long long i, long long s1, long long s2) {
  if (s1 == s2) {
    flag = 1;
    return;
  }
  if (i > c) return;
  sol(i + 1, s1 + a[i], s2);
  if (!flag) sol(i + 1, s1, s2 + a[i]);
  if (!flag) sol(i + 1, s1, s2);
}
int main() {
  long long w, m, p = 1, sum = 1, st;
  cin >> w >> m;
  if (w == 2 || w == 3) {
    cout << "YES" << endl;
    return 0;
  }
  while (p <= m) {
    if (sum == m) {
      cout << "YES" << endl;
      return 0;
    }
    a[++c] = p;
    p = p * w;
    sum += p;
  }
  a[++c] = p;
  if (sum == m) {
    cout << "YES" << endl;
    return 0;
  }
  sol(1, 0, m);
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
