#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>hash(m,0);
	while(n)
	{
		if(hash[n%m])break;
		hash[n%m]++;
		n=n/m;
	}
	if(n==0)cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
	
}
