#include <iostream>
using namespace std;
int main()
{
    int n,m;
    int a[500]={};
    cin >> n >> m;
    while(n){
        if (a[n%m]) {
            cout << "NO";
            return 0;
        }
        a[n%m]=1;
        n=n/m;
    }
    cout << "YES";
    return 0;
}