#include <bits/stdc++.h>
using namespace std;
long long power(long long m, long long n) {
  if (n == 0) return 1;
  return m * power(m, n - 1);
}
int main() {
  bool l = 0;
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i <= 100 && power(n, i) <= m; i++) {
    if (m % power(n, i + 1) == power(n, i))
      m -= power(n, i);
    else if (m % power(n, i + 1) == power(n, i + 1) - power(n, i))
      m += power(n, i);
    else if (m % power(n, i + 1) != 0) {
      l = 1;
      break;
    }
  }
  if (l == 0 && m == 0)
    cout << "yes";
  else
    cout << "no";
}
