#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ll a,b;
	cin>>a>>b;
	set<ll>s;
	ll cnt = 0;
	while(a)
	{
		cnt++;
		s.insert(a%b);
		a/=b;
	}
	if(cnt==s.size()) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}