#include <iostream>
#include <unordered_map>

using namespace std;

unordered_map <int, int> m;

int main()
{
    int a, b, r;
    bool Ok = false;
    cin >> a >> b;
    while(a){
        r = a % b;
        m[r]++;
        a/=b;
    }
    for(auto i:m){
        if(i.second != 1){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}
