import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);//new File("input.txt"));
	    PrintWriter pw = new PrintWriter(System.out);//new File("output.txt"));
	    int w = sc.nextInt(), m = sc.nextInt();
	    int flag = 1;
	    int a[] = new int[40];
	    for (int i = 0; i < 35; i++)
	    	a[i] = 0;
	    int sz = 0;
	    while (m > 0)
	    {
	    	a[sz++] = m%w;
	    	m /= w;
	    }
		for (int i = 0; i <= sz; i++)
			if (a[i] != 0 && a[i] != 1 && a[i] != w-1 && a[i] != w)
			{
			   flag = 0;
			   break;
	        }
	        else
	        {
				if (a[i] == w-1 || a[i] == w)
				   a[i+1]++;
	        }
		if (flag == 1)
		   pw.println("YES");
		else
			pw.println("NO");
	   pw.close();
	}
}
