#include <bits/stdc++.h>   using namespace std;   int w, m;   long long x = 1;   bool f = 1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> w >> m;     while (m && f) {       if ((m - 1) % w == 0 || m % w == 0 || (m + 1) % w == 0) {         if ((m - 1) % w == 0 || m % w == 0)           m /= w;         else           m = (m + 1) / w;       } else         f = 0;     }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }   