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

public class Main {

    static MyScanner in;
    static PrintWriter out;
    //static Timer t = new Timer();

    public static void main(String[] args) throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out, true);

        int w = in.nextInt(), m = in.nextInt();

        int[] arr = new int[100];
        int len = 0;

        while(m > 0) {
            arr[len++] = m % w;
            m /= w;
        }

        for(int i = 0; i < len; i++) {
            if(arr[i] == 0 || arr[i] == 1)
                continue;
            if(arr[i] == w || arr[i] == w - 1) {
                arr[i+1]++;
                continue;
            }

            out.println("NO");
            return;
        }

        out.println("YES");
        return;
    }
}

//<editor-fold defaultstate="collapsed" desc="MyScanner">
class MyScanner {

    private final BufferedReader br;
    private StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public MyScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(new File(path)));
        //br = new BufferedReader(new InputStreamReader(new FileInputStream(
        //new File(path)), "cp1251"));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements())
                st = new StringTokenizer(br.readLine());
        }
        catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }
}
//</editor-fold>


import java.io.*;
import java.util.*;
public class cf3082C{
    public static void main(String[] args) throws IOException {
    	Scanner f = new Scanner(System.in);
        StringTokenizer st = new StringTokenizer(f.nextLine());
        int w = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        f.close();

        //convert m to base w
        int r = m;
        int e = (int)(Math.log(r)/Math.log(w));
        int l = e;
        int[] digits = new int[l+2];
        while(e >= 0){
        	if(r - Math.pow(w, e) >= 0){
        		digits[e] = (int)(r / Math.pow(w,e)) % w;
        	}
        	e--;
        }
        /*for(int i = 0; i < l+2; i++){
        	System.out.print(digits[i] + " " );
        }*/

        boolean works = true;
        for(int i = 0; i < l+1; i++){
        	if(digits[i] >= w){
        		digits[i] %= w;
        		digits[i+1]++;
        	}
        	if(!(digits[i] == 0 || digits[i] == 1)){
        		digits[i]++;
        	}
        	if(digits[i] >= w){
        		digits[i] %= w;
        		digits[i+1]++;
        	}
        }

        /*for(int i = 0; i < l+2; i++){
    	System.out.print(digits[i] + " " );
        }*/
        for(int i = 0; i < l+2; i++){
        	if(!(digits[i] == 0 || digits[i] == 1)){
        		works = false;
        		break;
        	}
        }

        if(works){
        	System.out.println("YES");
        }
        else{
        	System.out.println("NO");
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class C {

    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter pw;
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        long w = nextLong();
        long m = nextLong();
        long[]cnt = new long[200];
        int p = 0;
        while (m > 0) {
            long k = m % w;
            cnt[p] += k;
            m /= w;
            p++;
        }
        for (int i = 0; i < 105; i++) {
            if (cnt[i] > 1) {
                if (cnt[i]==w) {
                    cnt[i] = 0;
                    cnt[i+1]++;
                    continue;
                }
                if (cnt[i]==w-1) {
                    cnt[i] = -1;
                    cnt[i+1]++;
                }
                else {
                    System.out.println("NO");
                    return;
                }
            }
        }
        for (int i = 0; i <= 100; i++) {
            if (Math.abs(cnt[i]) > 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
        pw.close();
    }
    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    private static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    private static String next() throws IOException {
        while (st==null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}


import java.io.*;
import static java.lang.Math.*;
import java.util.*;
import java.util.function.*;
import java.lang.*;

public class Main {
    final static boolean debug = false;
    final static String fileName = "";
    final static boolean useFiles = false;

    public static void main(String[] args) throws FileNotFoundException {
        PrintWriter writer = new PrintWriter(System.out);
        new Task(new InputReader(System.in), writer).solve();
        writer.close();
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public byte nextByte() {
        return Byte.parseByte(next());
    }
}

class Task {
    public void solve() {
        int w = in.nextInt();
        int m = in.nextInt();

        while (m != 0){
            if (m % w == 0 || m % w == 1){
                m /= w;
            }else if (m % w == w - 1){
                m = (m + 1) / w;
            }
            else{
                out.println("NO");
                return;
            }
        }
        out.println("YES");
    }

    private InputReader in;
    private PrintWriter out;

    Task(InputReader in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

/*
1000000000 2
1000000000 2
 */
public class E {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		long w=fs.nextInt(), m=fs.nextInt();
		if (w<=3) {
			System.out.println("YES");
			return;
		}
		int nDigits=0;
		long val=1;
		long[] bases=new long[100];
		while (val<=2e9) {
			bases[nDigits]=val;
			val*=w;
			nDigits++;
		}
		int[] values=new int[nDigits];
		Arrays.fill(values, -1);
		long curTotal=0;
		for (int i=0; i<nDigits; i++) curTotal-=bases[i];
		boolean works=false;
		outer:while (true) {
			int index=0;
			while (true) {
				values[index]++;
				curTotal+=bases[index];

				if (values[index]!=2) {
					if (Math.abs(curTotal)==m) {
//						System.out.println("Values: "+Arrays.toString(values));
						works=true;
					}
					break;
				}
				values[index]=-1;
				curTotal-=bases[index]*3;
				index++;
				if (index==nDigits) break outer;
			}
		}
		System.out.println(works?"YES":"NO");
	}

	static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;

public class sd {

	public static long max(long num, long num2)
	{
		return 1;
	}
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		Scanner s = new Scanner(System.in);
			//String s1 = br.readLine();
			int w = s.nextInt();
			int m = s.nextInt();
			boolean flag = true;
			int[] arr = new int[40];
			for(int i =0;i<35;i++)
				arr[i] = 0;
			int cntr = 0;
			while(m>0)
			{
				arr[cntr++] = m%w;
				m = m/w;
			}
			for(int i=0;i<=cntr;i++)
			{
				if(arr[i]!=0&&arr[i]!=1&&arr[i]!=w&&arr[i]!=w-1)
				{
					flag = false;
					break;
				}
				else
				{
					if(arr[i]==w||arr[i]==w-1)
					{
						arr[i+1]++;
					}
				}
			}

			if(flag)
				System.out.println("YES");
			else System.out.println("NO");
	}
}


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

public class CF552C{
  public static int k, w;
  public static HashSet<Long> set;
  public static void main(String[] args)throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    w = in.nextInt();
    long n = in.nextLong();

    k = 0;
    for(int i = 0; w > 2 && i < 21; i++){
      k = i;
      if(Math.pow(w, i) > 1e9){
        break;
      }
    }

    set = new HashSet<Long>();
    if(w > 2) solve(0, 0);

    boolean bol = false;
    if(w == 2) bol = true;

    for(long i : set){
      if(i >= n && set.contains(i-n)){
        bol = true;
        break;
      }
    }

    if(bol) pw.println("YES");
    else pw.println("NO");

    pw.close();
  }

  static void solve(int i, long sum){
    if(i > k){
      set.add(sum);
      return;
    }

    solve(i+1, sum+(long)Math.pow(w, i));
    solve(i+1, sum);
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next()throws Exception {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new StringTokenizer(reader.readLine());
      return tokenizer.nextToken();
    }

    public String nextLine()throws Exception {
      String line = null;
      tokenizer = null;
      line =  reader.readLine();
      return line;
    }

    public int nextInt()throws Exception {
      return Integer.parseInt(next());
    }

    public double nextDouble() throws Exception{
      return Double.parseDouble(next());
    }

    public long nextLong()throws Exception {
      return Long.parseLong(next());
    }

  }
}


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

public class R308qC {

	public static void main(String args[]) {
		InputReader in = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);

		int w = in.nextInt();
		int m = in.nextInt();

		if(w == 2){
			System.out.println("YES");
			return;
		}

		long up = (long)1e11;

		long pow[] = new long[21];
		pow[0] = 1;
		int n = 21;

		for(int i=1;i<21;i++){
			pow[i] = w * pow[i-1];
			if(pow[i] >= up){
				n = i + 1;
				break;
			}
		}

		int state[] = new int[n];

		for(int i=0;i<(1<<n);i++){
			long left = m,right = 0;
			for(int j=0;j<n;j++)
				if(((1<<j) & i) != 0){
					state[j] = 1;
					left += pow[j];
				}
				else{
					state[j] = 0;
					right += pow[j];
				}
			long left2 = left,right2 = right;
			if(left > right){
				long diff = left - right;
				for(int j=n-1;j>=0;j--){
					if(state[j] == 1 && pow[j] <= diff){
						diff -= pow[j];
						left -= pow[j];
					}
				}
			}
			if(right > left){
				long diff = right - left;
				for(int j=n-1;j>=0;j--){
					if(state[j] == 0 && pow[j] <= diff){
						diff -= pow[j];
						right -= pow[j];
					}
				}
			}
			if(left == right){
				System.out.println("YES");
				return;
			}
			if(right2 > left2){
				long diff = right2 - left2;
				for(int j=n-1;j>=0;j--){
					if(state[j] == 0 && pow[j] <= diff){
						diff -= pow[j];
						right2 -= pow[j];
					}
				}
			}
			if(left2 > right2){
				long diff = left2 - right2;
				for(int j=n-1;j>=0;j--){
					if(state[j] == 1 && pow[j] <= diff){
						diff -= pow[j];
						left2 -= pow[j];
					}
				}
			}
			if(left2 == right2){
				System.out.println("YES");
				return;
			}
		}

		p.println("NO");
		p.close();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			int res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

}


import java.util.Scanner;

public class Main {

	public void solve() {
		Scanner sc = new Scanner(System.in);
		long W = sc.nextLong();
		long M = sc.nextLong();
		int cur = 0;
		while (Math.pow(W, cur) < M) {
			cur++;
		}
		if (Math.pow(W, cur) == M) {
			System.out.println("YES");
			return;
		}

		long MAX = (long) Math.pow(W, cur);
		long sum = (MAX - 1) / (W - 1);
		if (MAX - sum == M) {
			System.out.println("YES");
			return;
		}
		if (dfs(W, M)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	private boolean dfs(long W, long M) {
		if (M == 1) {
			return true;
		}
		if (M % W == 0) {
			return dfs(W, M / W);
		} else if ((M - 1) % W == 0) {
			return dfs(W, (M - 1) / W);
		} else if ((M + 1) % W == 0) {
			return dfs(W, (M + 1) / W);
		}
		return false;
	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C {

	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}

	public static void main(String args[]) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		int W = sc.nextInt();
		if (W == 2) {
			System.out.println("YES");
			return;
		}
		int M = sc.nextInt();
		int[] d = new int[105];
		int exp = 0;
		while(M > 0) {
			d[exp] = M % W;
			M /= W;
			exp++;
		}
		for(int i = 0; i <= 100; i++){
			if (d[i] == (W - 1) || d[i] == W){
				d[i + 1]++;
			}
			else if (d[i] > 1){
				System.out.println("NO");
				return;
			}
		}
		if (d[101] > 0)
			System.out.println("NO");
		else
			System.out.println("YES");
	}

}


import java.util.*;
public class c {
public static void main(String[] args)
{
  Scanner input = new Scanner(System.in);
  int  w= input.nextInt(), m = input.nextInt();
  boolean good =true;
  ArrayList<Integer> digits = new ArrayList<Integer>();
  while(m > 0 && w != 2)
  {
    int x = m%w;
    if(x == w - 1) m++;
    else if(x == 1) m--;
    else if(x == 0) ;
    else good = false;
    //System.out.println(x);
    //digits.add(x);
    m /= w;
  }
  System.out.println(good ? "YES" : "NO");
}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args)throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] in = br.readLine().split(" ");
		int w = Integer.parseInt(in[0]);
		int m = Integer.parseInt(in[1]);
		int[] num = new int[105];
		int ind = 0;
		while(m!=0){
			num[ind++]=m%w;
			m/=w;
		}

		boolean flag=true;
		for(int i=0;i<101;i++){
			if(num[i]==0 || num[i]==1)continue;
			if(num[i]==w-1){
				int j=i+1;
				num[j]++;
				num[j]%=w;
				while(num[j]==0){
					num[++j]++;
					num[j]%=w;
				}
				continue;
			}
			flag=false;
			break;
		}
		if(!flag)
			System.out.println("NO");
		else
			System.out.println("YES");
	}
}


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

public class C
{
   public static void main(String[] args)
   {
      PrintWriter out = new PrintWriter(System.out);
      new C(new FastScanner(), out);
      out.close();
   }

   long[] sum;
   long[] exp;

   boolean go(long val, int i)
   {
      if (val == 0) return true;
      if (i == -1) return false;
      if (val > sum[i] || val < -sum[i])
         return false;

      boolean res = go(val+exp[i], i-1) || go(val-exp[i], i-1) || go(val, i-1);
      return res;
   }

   public C(FastScanner in, PrintWriter out)
   {
      int w = in.nextInt();
      int target = in.nextInt();
      if (w == 2 || w == 3)
      {
         out.println("YES");
         return;
      }

      long max = Math.min(w*1L*(target+w), Long.MAX_VALUE/w);
      //System.out.println(max);
      int cap = 0;
      long ee = 1L;
      while (ee < max)
      {
         ee *= w;
         cap++;
      }
      cap++;

      sum = new long[cap];
      exp = new long[cap];
      cap = 0;
      ee = 1L;
      while (cap < sum.length)
      {
         exp[cap] = ee;
         if (cap > 0)
            sum[cap] = sum[cap-1];
         sum[cap] += ee;
         ee *= w;
         cap++;
      }
      //System.out.println(Arrays.toString(sum));
      //System.out.println(Arrays.toString(exp));
      out.println(go(target, cap-1) ? "YES" : "NO");
   }
}

class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner()
    {
        stream = System.in;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Solution11 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int m = sc.nextInt();
		if(w < 4){
			System.out.println("YES");
			return;
		}
		while(m>0){
			int remainder = m%w;
			int next = m+1;
			if(remainder > 1 && remainder != w-1){
				System.out.println("NO");
				return;
			}
			m = next/w;
		}
		System.out.println("YES");
	}
}


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

public class Main {

    private static class FastReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public FastReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 1 << 16);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
                catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            try {
                return reader.readLine();
            }
            catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int w = in.nextInt(), m = in.nextInt();
        boolean res = true;
        boolean isPrevUsed = false;
        while (m > 0) {
            if (m % w == 0 || m % w - 1 == 0) {
                m /= w;
            }
            else if (m % w + 1 == w) {
                m++;
            }
            else {
                res = false;
                break;
            }
        }
        out.println(res ? "YES" : "NO");

        out.flush();
    }
}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int w = in.nextInt(), m = in.nextInt(), n = 0;
        int[] a = new int[50];
        do {
            a[++n] = m % w;
            m /= w;
        } while (m > 0);

        boolean ok = true;
        for(int i = 1; i <= n;)
            if (a[i] > 1) {
                a[i] += 1;
                if (a[i] == w) {
                    while (i <= n && a[i] >= w) {
                        a[i] = 0;
                        a[++i] += 1;
                    }
                }
                else ++i;
                if (a[i-1] > 1) {
                    ok = false; break;
                }
            } else ++i;
        if (ok) out.print("YES"); else out.print("NO");
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        } catch (Exception e) {
            throw new UnknownError(e.getMessage());
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class CF552C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int w = in.nextInt();
		int m = in.nextInt();
		in.close();

		int[] basew = new int[100];

		int counter = 0;

		while (m > 0) {
			int rem = m % w;
			basew[counter] = rem;
			m = m / w;
			counter++;
		}

		//System.out.println(Arrays.toString(basew));

		for (int i = 0; i < basew.length; i++) {
			if(basew[i] == 1 || basew[i] == 0 || basew[i] == -1) {
				continue;
			} else if(basew[i] == w - 1) {
				basew[i] -= w;
				basew[i + 1] = (basew[i + 1] + 1);
			} else if(basew[i] == w){
				basew[i] = 0;
				basew[i+1] = basew[i+1]+1;
			} else {
				System.out.println("NO");
				System.exit(0);
			}
		}
		//System.out.println(Arrays.toString(basew));
		System.out.println("YES");
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class C {

    static boolean convertAndCheck(int num, int base) {

        int [] digits = new int[50];

        int ind = 0;

        while(num > 0) {
            digits[ind++] = num%base;
            num/=base;
        }

        boolean succ = true;

        for(int i=0; i<ind; i++)  {
            if(digits[i] > 1 && digits[i] < base - 1)  {
succ = false;
break;
}

if(digits[i] == base-1 || digits[i] == base) {
    // if its base-1 we add 1 and increase the next one by one
    // if its already increased we increase it
digits[i+1]++;
}
        }

        return succ;
    }
    public static void main(String [] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int w, m;

        String [] parts = br.readLine().split(" ");

        w = Integer.parseInt(parts[0]);
        m = Integer.parseInt(parts[1]);

        boolean isValid = convertAndCheck(m, w);

        if(isValid) {

            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
    }
}


import java.util.*;
import java.io.*;
public class C {
    static HashMap<Long, Boolean> cache = new HashMap<>();
    static boolean poss(int k, int m, int w) {
        // k = 0 ~ 100
        if (k == 0) {
            if (-1 <= m && m <= 1) return true;
            else return false;
        }
        long key = 101L * m + k;
        if (!cache.containsKey(key)) {
            boolean ret = false;
            for (int i = -1; i <= 1; i++) {
                if ((m + i) % w == 0) {
                    int nm = (m + i) / w;
                    if (poss(k - 1, nm, w)) {
                        ret = true;
                        break;
                    }
                }
            }
            cache.put(key, ret);
        }
        return cache.get(key);
    }
    static void solve() {
        int w = in.nextInt();
        int m = in.nextInt();
        if (poss(100, m, w)) {
            out.println("YES");
        } else {
            out.println("NO");
        }
        for (int i = 0; i < 101; i++) {

        }

    }
    static PrintWriter out = new PrintWriter(System.out);
    static InputReader in = new InputReader(System.in);
    static void d(Object o) {
        out.println(o);
        out.flush();
    }
    public static void main(String args[]) {
        solve();
        out.close();
    }
}
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
	reader = new BufferedReader(new InputStreamReader(stream), 32768);
	tokenizer = null;
    }
    public String next() {
	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	    try {
		tokenizer = new StringTokenizer(reader.readLine());
	    } catch (IOException e) {
		throw new RuntimeException(e);
	    }
	}
	return tokenizer.nextToken();
    }
    public double nextDouble() {
	return Double.parseDouble(next());
    }
    public long nextLong() {
	return Long.parseLong(next());
    }
    public int nextInt() {
	return Integer.parseInt(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.*;

public class Main {

	static IO io;
	static int n;
	static long mod = 1000000007L;

	public static void main(String args[]) throws Exception{

		io = new IO();
		io.init();

		//----------------------------------------

		long w = io.nextLong();
		long m = io.nextLong();

		long res = m;

		int maxIndex = 100;

		while( res > 0 && maxIndex >= 0  ){

			//System.out.println( res +":" + maxIndex);
			long min = 1 ;
			long max = 1;

			long cur = 1;

			int i;
			for( i = 1 ;i <= maxIndex ; ++i ){

				if( min == res || max == res || cur == res ){
					System.out.println("YES");
					System.exit(0);
				}

				if( res < min ){
					System.out.println("NO");
					System.exit(0);

				}

				if( min < res &&  res < max){

					res =  Math.abs( cur - res );
					maxIndex = i-1;
					break;
				}

				else{

					cur = cur*w;

					min = cur - max;
					max = cur + max;
				}

			}

			if( i  == maxIndex){
			if( min == res || max == res || cur == res ){
				System.out.println("YES");
				System.exit(0);
			}

			if( res < min ){
				System.out.println("NO");
				System.exit(0);

			}

			if( min < res &&  res < max){

				res =  Math.abs( cur - res );
				maxIndex = maxIndex-1;
			}

			}
		}

		System.out.println("NO");

		//----------------------------------------
		io.destroy();
	}

	static long pow( long base , long exp){

		if( exp == 0 ) return 1;

		long temp = pow( base,exp/2);
		temp =temp*temp;

		if( exp%2 == 0 )
			return temp;
		else
			return temp*base;
	}

	static class IO{

		BufferedReader reader;
		StringTokenizer tokenizer;
		PrintWriter writer;

		public void init() {
			try {
				reader = new BufferedReader(new InputStreamReader(System.in),8*1024);
				writer = new PrintWriter(System.out);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(261);
			}
		}

		void destroy() {
			writer.close();
			System.exit(0);
		}

		void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		void println(Object... objects) {
			print(objects);
			writer.println();
		}

		String nextLine() throws IOException {
			return reader.readLine();
		}

		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(nextLine());
			return tokenizer.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextToken());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(nextToken());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(nextToken());
		}
	}
}


import java.util.*;

public class Main {

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);

		int w = sc.nextInt(), m = sc.nextInt();
		int a[] = new int[101];

		for(int i=0;i<=100;i++){
			a[i] = m%w;
			m/=w;
		}

		int c = 0;
		boolean s = true;
		for(int i=0;i<=100;i++){
			a[i] += c;
			c = a[i]/w;
			a[i] %= w;

			if(a[i]==1 || a[i]==0){
				continue;
			}
			else if(a[i] == w-1){
				c = 1;
			}
			else
			{
				s = false;
				break;
			}

		}

		System.out.print(s && c!=1?"YES":"NO");

	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.run();
    }

    public void run() throws Exception {
        PrintWriter pr = null;
        InputReader sc = null;

        pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        sc = new InputReader(System.in);
        //sc = new InputReader(new FileInputStream(new File("input.txt")));

        int n = sc.nextInt();
        int m = sc.nextInt();

        // convert m to index n
        List<Integer> radix = new ArrayList<Integer>();
        int k = m;
        while (k > 0) {
            radix.add(k%n);
            k /= n;
        }

        // prevent array overflow at the end
        radix.add(0);
        boolean res = true;
        for (int i = 0; i < radix.size()-1; i++) {
            int c = radix.get(i);
            if (c == 0 || c == 1 || c == n-1 || c == n) {
                if (c == n-1 || c == n) {
                    radix.set(i+1, radix.get(i+1) + 1);
                }
            } else {
                res = false;
                break;
            }
        }

        if (res) {
            pr.println("YES");
        } else {
            pr.println("NO");
        }

        pr.close();
    }

    long pow(int a, int n) {
        long res = 1L;
        for (int i = 1; i <= n; i++) {
            res *= a;
        }
        return res;
    }

    static class InputReader {
        public BufferedReader reader;

        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
                catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

}


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

public class BasicJava
{
   public static void main(String[] args)
   {
      Task Main = new Task();

      Main.solve();
   }

   public static class Task
   {
      public InputReader in = new InputReader(System.in);
      public PrintWriter out = new PrintWriter(System.out);

      public void solve()
      {
         int w = in.nextInt();
         int m = in.nextInt();

         int[] t = new int[110];

         int nr = 0;

         while (m > 0) {

            nr++; t[nr] = m % w;

            m = m / w;

         }

         for (int i = 1; i <= nr; i++)
            if (t[i] > w / 2) {

               t[i] = - (t[i] - w);

               t[i + 1] ++;

            }

         if (t[nr] == 1) nr++;

         for (int i = 1; i <= nr; i++)
            if (t[i] > 1) {

               System.out.println("NO");

               System.exit(0);

            }

         System.out.println("YES");

      }
   }

   static class InputReader
   {
      private InputStream stream;
      private byte[] buf = new byte[2048];
      private int curChar;
      private int numChars;

      public InputReader(InputStream stream)
      {
         this.stream = stream;
      }

      public int read()
      {
         if (numChars == -1)
            throw new UnknownError();
         if (curChar >= numChars)
         {
            curChar = 0;
            try
            {
               numChars = stream.read(buf);
            }
            catch (IOException e)
            {
               throw new UnknownError();
            }
            if (numChars <= 0)
               return -1;
         }
         return buf[curChar++];
      }

      public int peek()
      {
         if (numChars == -1)
            return -1;
         if (curChar >= numChars)
         {
            curChar = 0;
            try
            {
               numChars = stream.read(buf);
            }
            catch (IOException e)
            {
               return -1;
            }
            if (numChars <= 0)
               return -1;
         }
         return buf[curChar];
      }

      public void skip(int x)
      {
         while (x-- > 0)
            read();
      }

      public int nextInt()
      {
         return Integer.parseInt(next());
      }

      public long nextLong()
      {
         return Long.parseLong(next());
      }

      public String nextString()
      {
         return next();
      }

      public String next()
      {
         int c = read();
         while (isSpaceChar(c))
            c = read();
         StringBuffer res = new StringBuffer();
         do
         {
            res.appendCodePoint(c);
            c = read();
         }
         while (!isSpaceChar(c));

         return res.toString();
      }

      public String nextLine()
      {
         StringBuffer buf = new StringBuffer();
         int c = read();
         while (c != '\n' && c != -1)
         {
            if (c != '\r')
               buf.appendCodePoint(c);
            c = read();
         }
         return buf.toString();
      }

      public double nextDouble()
      {
         int c = read();
         while (isSpaceChar(c))
            c = read();
         int sgn = 1;
         if (c == '-')
         {
            sgn = -1;
            c = read();
         }
         double res = 0;
         while (!isSpaceChar(c) && c != '.')
         {
            if (c == 'e' || c == 'E')
               return res * Math.pow(10, nextInt());
            if (c < '0' || c > '9')
               throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
         }
         if (c == '.')
         {
            c = read();
            double m = 1;
            while (!isSpaceChar(c))
            {
               if (c == 'e' || c == 'E')
                  return res * Math.pow(10, nextInt());
               if (c < '0' || c > '9')
                  throw new InputMismatchException();
               m /= 10;
               res += (c - '0') * m;
               c = read();
            }
         }
         return res * sgn;
      }

      public boolean hasNext()
      {
         int value;
         while (isSpaceChar(value = peek()) && value != -1)
            read();
         return value != -1;
      }

      private boolean isSpaceChar(int c)
      {
         return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }

   }

}


//################################################################################################################
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.util.InputMismatchException;

//################################################################################################################
public class R308D2C {
	public static void main(String[] args) {
		R308D2C c = new R308D2C();
		InputReader1 reader = c.new InputReader1(System.in);
		OutputWriter writer = c.new OutputWriter(System.out);
		// think about the brute-force approach
		// read input
		// code boundary conditions
		int w = reader.readInt();
		int m = reader.readInt();
		boolean ans = trysolve(w, m);
		if (ans) {
			writer.println("YES");
		} else {
			writer.println("NO");
		}
		reader.close();
		writer.close();
	}

	public static boolean trysolve(int w, int m) {
		return (w <= 3 || m == 1 || solve(w, m - 1) || solve(w, m) || solve(w,
				m + 1));
	}

	public static boolean solve(int w, int m) {
		return (m % w == 0 && trysolve(w, m / w));
	}

	class InputReader1 {
		// private final boolean finished = false;

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader1(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int peek() {
			if (numChars == -1)
				return -1;
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					return -1;
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int length = readInt();
			if (length < 0)
				return null;
			byte[] bytes = new byte[length];
			for (int i = 0; i < length; i++)
				bytes[i] = (byte) read();
			try {
				return new String(bytes, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				return new String(bytes);
			}
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public boolean isExhausted() {
			int value;
			while (isSpaceChar(value = peek()) && value != -1)
				read();
			return value == -1;
		}

		public String next() {
			return readString();
		}

		public boolean readBoolean() {
			return readInt() == 1;
		}

		public void close() {
			try {
				stream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream stream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
					stream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void println(String s) {
			writer.println(s);
		}

		public void println(int x) {
			writer.println(x);
		}

		public void print(int x) {
			writer.print(x);
		}

		public void println(long x) {
			writer.println(x);
		}

		public void printSpace() {
			writer.print(" ");
		}

		public void close() {
			writer.close();
		}
	}
}


import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int w = scanner.nextInt();
		int m = scanner.nextInt();

		while (m > 1) {
			if (m % w == 0)
				m = m / w;
			else if ((m + 1) % w == 0)
				m = (m + 1) / w;
			else if ((m - 1) % w == 0)
				m = (m - 1) / w;
			else
				break;
		}

		if (m > 1)
			System.out.println("NO");
		else
			System.out.println("YES");

		scanner.close();
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	public static void main(String args[])throws IOException{
		Reader in=new Reader();
		int w = in.nextInt();
		int m = in.nextInt();
		boolean ans=get(w,m)||get(w,m-1)||get(w,m+1);
		if(ans)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	static boolean get(int w,int m){
		if(m==0)
			return true;
		if(m%w!=0)
			return false;
		m=m/w;
		if(m==1)
			return true;
		return get(w,m)||get(w,m-1)||get(w,m+1);
	}
}
// 3,2 3,1 3,3


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

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	while (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    private long nextLong() throws Exception {
        return Long.parseLong(next());
    }

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);

        long w = nextLong(), M = nextLong();
        if (w == 2) {
            out.println("YES");
            out.close();
            return;
        }
        List<Long> a = new ArrayList<>();
        long p = 1;
        while(p <= M) {
            a.add(p);
            p *= w;
        }

        int n = a.size();
        // System.out.println(a);
        for(int mask = 0; mask < (1 << n); ++mask) {
            long sum = M;
            for(int i = 0; i < n; ++i) {
                if (((mask >> i) & 1) > 0) {
                    sum += a.get(i);
                }
            }
            boolean ok = true;
            int j = 0;
            while(sum > 0) {
                int rem = (int)(sum % w);
                sum /= w;
                if (rem != 0 && rem != 1) {
                    ok = false;
                    break;
                }
                if (rem == 1 && ((mask >> j) & 1) > 0) {
                    ok = false;
                    break;
                }
                ++j;
            }
            if (ok) {
                out.println("YES");
                out.close();
                return;
            }
        }

        out.println("NO");
        out.close();
    }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner fi = new Scanner(System.in);
        PrintWriter fo = new PrintWriter(System.out);
        int w = fi.nextInt(), m = fi.nextInt(), res = 1;
        while (m != 0){
            int tmp = m % w;
            if (tmp == w - 1 && tmp != 1) m = (m + 1) / w;
            else
                if (tmp == 1) m /= w;
                else
                    if (tmp != 0){
                        res = 0;
                        break;
                    }
                    else m /= w;
        }
        if (res == 1) fo.print("YES");
        else fo.print("NO");
        fi.close();
        fo.close();
    }
}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    private static int weight;
    private static int itemMass;
    private static boolean[] arr=new boolean[100];
    static{
        for(int i=0;i<100;i++)
            arr[i]=false;
    }
    public boolean isBalanced(){
        boolean isBalance=false;
        long pod1=itemMass, pod2=0;

        while(true){
            if(pod1>pod2){
                long nextMass=getMass(pod1-pod2);
                //System.out.println("Pod1 wieght is higher: "+nextMass);
                if(nextMass!=0){
                    pod2+=nextMass;
                }
                else
                    break;
            }
            else if(pod1<pod2){
                long nextMass1=getMass(pod2-pod1);
                //System.out.println("Pod2 wieght is higher: "+nextMass1);
                if(nextMass1!=0){
                    pod1+=nextMass1;
                }
                else
                    break;
            }
            else{
                isBalance=true;
                break;
            }
        }
        return isBalance;
    }

    public long getMass(long mass){
        long result;
        int logBase=(int) (Math.log(mass)/Math.log(weight));
        //System.out.println("Mass is "+mass+" log is: "+logBase);
        //long sumTotal=((long) Math.pow(weight, logBase+1)-1)/(weight-1);

        BigInteger bi=new BigInteger(Integer.toString(weight));
        //System.out.println(bi.toString());
        bi=bi.pow(logBase+1);
        //System.out.println(bi.toString());
        bi=bi.subtract(new BigInteger(Integer.toString(1)));
        //System.out.println(bi.toString());
        bi=bi.divide(new BigInteger(Integer.toString(weight-1)));
        //System.out.println(bi.toString());
        long sumTotal=bi.longValue();

        //System.out.println("Mass is "+mass+" log is: "+logBase+" total mass is: "+sumTotal+" arr value: "+arr[logBase+1]+" "+arr[logBase]);
        if(mass>sumTotal && !arr[logBase+1]){
            result=(int) Math.pow(weight, logBase+1);
            arr[logBase+1]=true;
        }
        else if(mass<=sumTotal && !arr[logBase]){
            result=(int) Math.pow(weight, logBase);
            arr[logBase]=true;
        }
        else{
            result=0;
        }

        return result;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        Main.weight=sc.nextInt();
        Main.itemMass=sc.nextInt();
        Main wb=new Main();

        if(wb.isBalanced())
            System.out.println("YES");
        else
            System.out.println("NO");
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
public class question{
	public static void main(String args[])throws Exception{
		Scanner sc = new Scanner(System.in);
		BigInteger w = new BigInteger(Integer.toString(sc.nextInt()));
		BigInteger m = new BigInteger(Integer.toString(sc.nextInt()));
		BigInteger num = (w.pow(101)).subtract(new BigInteger("1"));
		BigInteger den = w.subtract(new BigInteger("1"));
		BigInteger toAdd = num.divide(den);
		BigInteger target = m.add(toAdd);
		for(int i=0; i<=101; i++){
			BigInteger digit = target.mod(w);
			int digitInt = digit.intValue();
			if(digitInt > 2){
				System.out.println("NO");
				return;
			}
			target = target.divide(w);
		}
		System.out.println("YES");
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Solution {
    public static boolean solve(int w,int m){
        return w<=3||m==1||trysolve(w,m-1)||trysolve(w,m+1)||trysolve(w,m);
    }
    public static boolean trysolve(int w,int m){
        return m%w==0 && solve(w,m/w);
    }
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out,true);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int w = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        if(solve(w,m))out.println("YES");
        else out.println("NO");
    }
}


import java.util.Scanner;

public class VanyaandScales {
	static int w;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		w = in.nextInt();
		int m = in.nextInt();
		int bitmask = 0;
		System.out.println(check(m, bitmask) ? "YES" : "NO");

	}

	public static boolean check(int m, int mask) {
		// System.out.println(m + ":" + Integer.toBinaryString(mask));
		int pos = (int) Math.floor(Math.log(m) / Math.log(w));
		if (((mask >> pos) & 1) == 1)
			return false;
		if (m - Math.pow(w, pos) == 0)
			return true;
		boolean s1 = (((mask >> pos) & 1) == 1 ? false : check(
				(int) (m - Math.pow(w, pos)), mask | (1 << pos)));
		boolean s2 = ((mask >> (pos + 1)) & 1) == 1 ? false : check(
				(int) (Math.pow(w, pos + 1) - m), mask | (1 << (pos + 1)));
		return s1 || s2;
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author xwchen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        long[] sum = new long[105];
        long[] pw = new long[105];
        boolean OK = false;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long w = in.nextLong();
            long m = in.nextLong();
            long p = 1;
            int mx = 0;
            for (int i = 0; i < 100; ++i) {
                sum[i + 1] = p + sum[i];
                pw[i] = p;
                p *= w;
                if (p > 1L << 40) {
                    mx = i;
                    break;
                }
            }
            process(0, m, mx);
            out.println(OK ? "YES" : "NO");
        }

        void process(long cur, long target, int pos) {
            //System.out.println("cur = " + cur + " pos = " + pos);

            if (cur == target) {
                OK = true;
                return;
            }
            long remaining = sum[pos + 1];
            long next = pw[pos];

            //System.out.println("remaining = " + remaining + " next = " + next);
            if (cur - remaining > target) {
            } else if (cur + remaining < target) {
            } else {
                if (cur + sum[pos] < target) {
                    process(cur + next, target, pos - 1);
                } else if (cur - sum[pos] > target) {
                    process(cur - next, target, pos - 1);
                } else {
                    process(cur, target, pos - 1);
                }
            }
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

        public String next() {
            while (!tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


// Problem : C. Vanya and Scales
// Contest : Codeforces Round #308 (Div. 2)
// URL : https://codeforces.com/contest/552/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

public class a {
    public static void main(String[] args) throws IOException {
        FastReader scan = new FastReader();
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("taming.out")));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        Task solver = new Task();
        //int t = scan.nextInt();
        int t = 1;
        for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
        out.close();
    }
    static class Task {
    	long n, m;
        public void solve(int testNumber, FastReader sc, PrintWriter pw) {
    		n = sc.nextInt();
    		m = sc.nextInt();
    		long[] base = new long[32];
    		for(int i=0;i<30;i++){
    			base[i]=m%n;
    			m/=n;
    		}
    		for(int i=0;i<30;i++){
    			if(base[i]<=1){
    				continue;
    			}
    			else if(base[i]==n){
    				base[i+1]++;
    			}
    			else if(base[i]==n-1){
    				base[i+1]++;
    			}
    			else{
    				pw.println("NO");
    				return;
    			}
    		}
    		pw.println("YES");
        }

    }
    static class tup implements Comparable<tup>{
        int a, b,c;
        tup(){};
        tup(int a, int b, int c){
            this.a=a;
            this.b=b;
            this.c=c;
        }

        @Override
        public int compareTo( tup o2) {
            return o2.b!=b?Integer.compare(o2.b,b):Integer.compare(o2.a,a);
        }
    }
    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.*;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Stream;

public class Main implements Runnable {
    static final int MOD = (int) 1e9 + 7;
    static final int MI = (int) 1e9;
    static final long ML = (long) 1e18;
    static final Reader in = new Reader();
    static final PrintWriter out = new PrintWriter(System.out);
    StringBuilder answer = new StringBuilder();

    public static void main(String[] args) {
        new Thread(null, new Main(), "persefone", 1 << 32).start();
    }

    @Override
    public void run() {
        solve();
        printf();
        flush();
    }

    void solve() {
        int w = in.nextInt();
        int m = in.nextInt();
        if (w <= 3) {
            printf("YES");
            return;
        }

        long limit = (long) 1e10;
        long x = 1;
        List<Long> list = new ArrayList<>();
        do {
            list.add(x);
            x *= w;
        } while (x <= limit);

        long[] a = list.stream().mapToLong(Long::longValue).toArray();
        int n = a.length;
        for (int i = 0; i < 1 << n; i++) {
            long v = m;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) > 0) {
                    v += a[j];
                }
            }
            for (int j = n - 1; j >= 0; j--) {
                if ((i & (1 << j)) == 0) {
                    if (v - a[j] >= 0) {
                        v -= a[j];
                    }
                }
            }
            if (v == 0) {
                printf("YES");
                return;
            }
        }
        printf("NO");
    }

    void printf() {
        out.print(answer);
    }

    void close() {
        out.close();
    }

    void flush() {
        out.flush();
    }

    void printf(Stream<?> str) {
        str.forEach(o -> add(o, " "));
        add("\n");
    }

    void printf(Object... obj) {
        printf(false, obj);
    }

    void printfWithDescription(Object... obj) {
        printf(true, obj);
    }

    private void printf(boolean b, Object... obj) {

        if (obj.length > 1) {
            for (int i = 0; i < obj.length; i++) {
                if (b) add(obj[i].getClass().getSimpleName(), " - ");
                if (obj[i] instanceof Collection<?>) {
                    printf((Collection<?>) obj[i]);
                } else if (obj[i] instanceof int[][]) {
                    printf((int[][]) obj[i]);
                } else if (obj[i] instanceof long[][]) {
                    printf((long[][]) obj[i]);
                } else if (obj[i] instanceof double[][]) {
                    printf((double[][]) obj[i]);
                } else printf(obj[i]);
            }
            return;
        }

        if (b) add(obj[0].getClass().getSimpleName(), " - ");
        printf(obj[0]);
    }

    void printf(Object o) {
        if (o instanceof int[])
            printf(Arrays.stream((int[]) o).boxed());
        else if (o instanceof char[])
            printf(new String((char[]) o));
        else if (o instanceof long[])
            printf(Arrays.stream((long[]) o).boxed());
        else if (o instanceof double[])
            printf(Arrays.stream((double[]) o).boxed());
        else if (o instanceof boolean[]) {
            for (boolean b : (boolean[]) o) add(b, " ");
            add("\n");
        } else
            add(o, "\n");
    }

    void printf(int[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(long[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(double[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(boolean[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(Collection<?> col) {
        printf(col.stream());
    }

    <T, K> void add(T t, K k) {
        if (t instanceof Collection<?>) {
            ((Collection<?>) t).forEach(i -> add(i, " "));
        } else if (t instanceof Object[]) {
            Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
        } else
            add(t);
        add(k);
    }

    <T> void add(T t) {
        answer.append(t);
    }

    static class Reader {
        private BufferedReader br;
        private StringTokenizer st;

        Reader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String fileName) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(fileName));
        }

        boolean isReady() throws IOException {
            return br.ready();
        }

        String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(br.readLine());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}


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

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter printWriter = new PrintWriter(System.out);

        int w = scanner.nextInt(), m = scanner.nextInt();
        boolean flag = true;
        int sz = 0;
        int[] a = new int[40];

        for (int i = 0; i < 40; i++)
        {
            a[i] = 0;
        }

        while (m > 0)
        {
            a[sz++] = m % w;
            m /= w;
        }

        for (int i = 0; i < sz; i++)
        {
            if (a[i] != 1 && a[i] != 0 && a[i] != w - 1 && a[i] != w)
            {
                flag = false;
                break;
            }
            else if (a[i] == w || a[i] == w - 1)
            {
                a[i + 1]++;
            }
        }

        if (flag) {
            printWriter.println("YES");
        }
        else {
            printWriter.println("NO");
        }
        printWriter.close();
    }
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alejandro Lopez
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long w = in.nextInt();
            long m = in.nextInt();

            if (w == 2) {
                out.println("YES");
                return;
            }

            long[] p = new long[30];
            p[0] = 1;
            int n = 1;
            while (n <= 20 && p[n - 1] * w < 1e12) {
                p[n] = p[n - 1] * w;
                ++n;
            }

            long[] sum = new long[1 << n];
            for (int i = 0; i < 1 << n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if ((i & (1 << j)) != 0) {
                        sum[i] += p[j];
                    }
                }
            }

            for (int i = 0; i < 1 << n; ++i) {
                long target = sum[i] + m;
                int lo = 0;
                int hi = (1 << n) - 1;
                while (lo <= hi) {
                    int mid = (lo + hi) / 2;
                    if (sum[mid] == target) {
                        if ((mid & i) == 0) {
                            out.println("YES");
                            return;
                        } else {
                            break;
                        }
                    } else if (sum[mid] < target) {
                        lo = mid + 1;
                    } else {
                        hi = mid - 1;
                    }
                }
            }

            out.println("NO");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


//package codeforcespractice;
import java.io.*;
import java.util.*;
public class vanyaandscale {
static long[] a;
static boolean ans;
static int n;
static long leftsum,rightsum;
public static void main(String[] arg) throws Exception
{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st=new StringTokenizer(br.readLine());
    long w=Long.parseLong(st.nextToken());
    long m=Long.parseLong(st.nextToken());
    long limit=(long)1e11;
    a=new long[40];
    int z=1;
    long temp=1;
    a[0]=1;
    if(w<=3)
    {
        System.out.println("YES");
        System.exit(0);
    }
    for(int i=1;i<16;i++)
    {
        a[z]=temp*w;
        temp=temp*w;
        if(temp>limit)
        {
            break;
        }
        z++;
    }

    leftsum=0;
    rightsum=m;
    n=z;
    pos(0);
    //System.out.println("hello");
    if(ans)
    {
        System.out.println("YES");
    }
    else
    {
        System.out.println("NO");
    }

}
public static void  pos(int x)
{
    if(x==n)
    {
        if(leftsum==rightsum)
        {
            //System.out.println("left sum is special "+leftsum+" rightsum is"+rightsum);
            ans=true;
        }
        return;
    }
    //System.out.println("left sum is"+leftsum+" right sum is"+rightsum);
    if(ans)
    {
        return;
    }
    else
    {
        for(int i=0;i<3;i++)
        {
            if(ans)
            {
                return;
            }
            if(i==1)
            {
                leftsum+=a[x];
                pos(x+1);
                leftsum-=a[x];
            }
            else if(i==2)
            {
                rightsum+=a[x];
                pos(x+1);
                rightsum-=a[x];
            }
            else
            {
                pos(x+1);
            }
        }
    }
}
}


import java.util.Scanner;

public class Proezd {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner in= new Scanner(System.in);
		long w=in.nextLong();
		long m=in.nextLong();
		long z=m;

		long u=1;

		boolean yeap=true;
		boolean flap=true;
	if (w!=2)
		while(z/u!=1)
		{ u=u*w;
		if (z>=u){
			long lo=z%u;
			if (lo==(u/w)||lo==(u-u/w))
			{
				if (lo==u/w) z=z-u/w;
				if (lo==u-u/w)z=z+u/w;
			}

                else if (lo==0) z=z;
                else flap=false;
                }

			else if (u>z)
			{
				long no=u%z;
				if (no==u/w){ z=z+u/w;}
                                else flap=false;
			}

			if (!flap) {break;}
		}

if (flap)
System.out.print("YES");
else System.out.print("NO");
		}

	}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;

import javax.management.RuntimeErrorException;

public class Codeforces {

    StringTokenizer tok;
    BufferedReader in;
    PrintWriter out;

    final boolean OJ = System.getProperty("ONLINE_JUDGE") != null;

    void init() {
        try {
            if (OJ) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    public static void main(String[] args) {
        new Codeforces().run();
    }

    void run() {
        init();
        solve();
        out.close();
    }

    void solve() {
        int w = readInt();
        int m = readInt();
        int[] a = new int[102];
        int rm = m;
        for (int i=0;i<=100;i ++) {
            a[i] = rm % w;
            rm /= w;
        }
        boolean[] need = new boolean[102];

        for (int i=0;i<=100;i++) {
            if (a[i] <= 1) continue;
            if (a[i] == w) {
                a[i + 1]++;
                continue;
            }
            if (a[i] != w - 1) {
                out.println("NO");
                return;
            }
            a[i] = 0;
            a[i + 1]++;
            need[i] = true;
        }
        need[101] = true;

        for (int i=0;i<102;i++) {
            if (a[i] == 1 && need[i]) {
                out.println("NO");
                return;
            }
        }
        out.println("YES");
    }

}


import java.io.IOException;
import java.util.InputMismatchException;

public class VanyaAndScales {
    public static void main(String[] args) {
        FasterScanner sc = new FasterScanner();

        int W = sc.nextInt();
        int M = sc.nextInt();

        int[] B = new int[101];
        int tmp = M;
        for (int i = 0; i < 100; i++) {
        	B[i] = tmp % W;
        	tmp /= W;
        }

        for (int i = 0; i < 100; i++) {
        	if (B[i] > 1) {
        		B[i] -= W;
        		B[i + 1]++;
        	}
        }

        for (int i = 0; i <= 100; i++) {
        	if (B[i] < -1 || B[i] > 1) {
        		System.out.println("NO");
        		return;
        	}
        }
        System.out.println("YES");
    }

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

	    public int[] nextIntArray(int n) {
	        int[] arr = new int[n];
	        for (int i = 0; i < n; i++) {
	            arr[i] = nextInt();
	        }
	        return arr;
	    }

		public long[] nextLongArray(int n) {
		    long[] arr = new long[n];
		    for (int i = 0; i < n; i++) {
		        arr[i] = nextLong();
		    }
		    return arr;
		}

	    private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}


import java.util.*;
import java.math.*;
import java.io.*;
public class Main{static long[] hum;
    public static void main(String[] args)  throws IOException {
        input.init(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int w= input.nextInt();
        int m=input.nextInt();
        int flag=0;
        int fg=0;

        for(int i=1;i<=100;i++){
        if(m%w==0)
            m/=w;
        else if((m+1)%w==0)
            m=(m+1)/w;
        else if((m-1)%w==0)
            m=(m-1)/w;
        else{
            flag=1;
        break;}
        if(m==0)
            break;
        if(i==100&&(!(m==1||m==0)))
            flag=1;

        }
        if(flag==1)
            System.out.println("NO");
        else
            System.out.println("YES");

    }
    public static class input {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] tmp = br.readLine().split(" ");
        int w = Integer.parseInt(tmp[0]), m = Integer.parseInt(tmp[1]);
        boolean ok = true;
        ArrayList<Integer> all = new ArrayList<Integer>();
        while (m != 0) {
            all.add(m % w);
            m /= w;
        }

        for (int i = 0; i < all.size(); ++i) {
            if (all.get(i) == 0 || all.get(i) == 1)
                continue;
            if (all.get(i) == w - 1) {
                int j = i + 1;
                while (j < all.size()) {
                    if (all.get(j) == w - 1) {
                        all.set(j, 0);
                    } else {
                        all.set(j, all.get(j) + 1);
                        break;
                    }
                    ++j;
                }
                continue;
            }
            ok = false;
            break;
        }

        if (ok)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


/* SEE wrick's comment in editorail section (nice explanation)

*/
import java.io.*;
import java.util.*;
public class gfg{

    static boolean solve(long w, long m) {
           return w <= 3 || m == 1 || trySolve(w, m-1) || trySolve(w, m) || trySolve(w, m+1) ;
       }

    static  boolean trySolve(long w, long m) {
                    return m%w == 0 && solve(w, m/w) ;
         }
       public static void main(String[] args){
           PrintWriter out = new PrintWriter(System.out);
                  long w = nl();
                  long m = nl();
              if(solve(w,m)==true)
                    out.println("YES");
              else
                    out.println("NO");

                  out.flush();
    }
    static FastReader sc=new FastReader();

      static int ni(){
                 int x = sc.nextInt();
                 return(x);
        }
      static long nl(){
              long x = sc.nextLong();
              return(x);
         }
      static String n(){
                 String str = sc.next();
                     return(str);
       }
     static String ns(){
                 String str = sc.nextLine();
                   return(str);
      }
     static double nd(){
               double d = sc.nextDouble();
                 return(d);
       }
  static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.Scanner;

public class weight {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		final int w = scanner.nextInt();
		final int m = scanner.nextInt();
		long[] weights = new long[100];
		long[] wSums = new long[100];
		boolean[] used = new boolean[100];
		long wt = 1, wSum = 0;
		for (int i = 1; i < 100; i++, wt *= w) {
			weights[i] = wt;
			wSum += wt;
			wSums[i] = wSum;
		}
		boolean found = false;
		long left = m;

		if (w == 2)
			found = true;

		SEARCH: while (!found) {
			for (int i = 0; i < 100; i++) {
				if (left <= weights[i]) {
					// see which side is closer
					if (weights[i] - left <= wSums[i - 1]) {
						if (used[i]) {
							break SEARCH;
						}
						left = weights[i] - left;
						used[i] = true;
					} else if (left <= wSums[i - 1]) {
						if (used[i - 1]) {
							break SEARCH;
						}
						left -= weights[i - 1];
						used[i - 1] = true;
					} else {
						break SEARCH;
					}
					break;
				}
			}
			found = (left == 0);
		}
		if (found)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


//package CF;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int w = sc.nextInt(), m = sc.nextInt();
		int[] c = new int[35];
		int tmp = m, ind = 0;
		boolean f = true;
		while (tmp > 0) {
			c[ind] += tmp % w;
			if(c[ind] == w){
				c[ind] = 0;
				c[ind+1]++;
			}
			if(c[ind] > 1){
				if(c[ind] == w-1)
				{
					c[ind+1]++;
				}
				else{
					f = false;
					break;
				}
			}
			tmp /= w;
			ind++;
		}
		out.println(f?"YES":"NO");
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


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

public class A {
    private FastScanner in;
    private PrintWriter out;

    void solve() {
        int k = in.nextInt();
        long pa = in.nextInt();
        long pb = in.nextInt();
        final int mod = (int) 1e9 + 7;
        BigInteger MOD = BigInteger.valueOf(mod);
        int inv = BigInteger.valueOf(pa + pb).modInverse(MOD).intValue();
        pa = (int) ((pa * 1L * inv) % mod);
        pb = (int) ((pb * 1L * inv) % mod);
        long[][] dp = new long[k + 1][k];
        dp[1][0] = 1;
        long res = 0;
        long sInv = BigInteger.valueOf((mod - pa + 1) % mod).modInverse(MOD).intValue();
        for (int cntA = 0; cntA <= k; cntA++) {
            for (int curK = 0; curK < k; curK++) {
                long pr = dp[cntA][curK];
                if (pr == 0) {
                    continue;
                }
                if (cntA != k) {
                    dp[cntA + 1][curK] = (int) ((dp[cntA + 1][curK] + pr * pa) % mod);
                } else {
                    long tmpPR = (int) (pr * pa % mod);
                    res += tmpPR * curK % mod;
                    tmpPR = (int) (tmpPR * pb % mod);
                    res += cntA *sInv % mod * tmpPR % mod;
                    res += sInv * sInv % mod * tmpPR % mod;
                    res %= mod;
                }
                if (curK + cntA >= k) {
                    res = (res + pr * pb % mod * (curK + cntA)) % mod;
//                    System.err.println("add " + res);
                } else {
                    dp[cntA][curK + cntA] = ((dp[cntA][curK + cntA] + pr * pb) % mod);
                }
            }
        }
        out.println(res % mod);
    }

    private void run() {
        try {
            in = new FastScanner(new File("A.in"));
            out = new PrintWriter(new File("A.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new A().runIO();
    }
}