#include <bits/stdc++.h>   long long int power(long long int x, long long int b) {     long long int p = 1;     while (b > 0) {       if (b & 1) {         p = p * x;         p %= 1000000007;       }       b >>= 1;       x *= x;       x %= 1000000007;     }     return p % 1000000007;   }   using namespace std;   struct lex_compare {     bool operator()(         const pair<long long int, pair<long long int, long long int> > p1,         const pair<long long int, pair<long long int, long long int> > p2) {       return (p1.first == p2.first) ? p1.second.first < p2.second.first                                     : p1.first > p2.first;     }   };   long long int n, m, b, mo;   long long int dp[2][500 + 1][500 + 1];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int w, m;     cin >> w >> m;     bool f = 1;     map<long long int, long long int> coeff;     long long int term = 1;     while (m >= term && term <= 10000000000) {       long long int x = (term * (m / term) - (w * term) * (m / (w * term)));       x /= term;       if (x <= 1) {         term *= w;       } else {         if (x != (w - 1)) {           f = 0;           break;         } else {           m += (w * term - term);         }         term *= w;       }     }     if (f)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }   