

Input

The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.

Output

Output "YES" or "NO".

Examples

Input


2 3


Output


YES


Input


3 2


Output


NO


Input


33 16


Output


YES


Input


26 5


Output


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

public class XenolithHippodrome {
	static FastReader sc = new FastReader();

	static void input(long a[]) {
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
	}

	static void input(int a[]) {
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
	}

	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;
		}
	}

	static String check(int n, int m) {
		String ans = "YES";
		HashSet<Integer> hs = new HashSet<>();

		while (n > 0) {
			int k = n % m;
//			System.out.println(k + " " + n + " " + m);
			if (hs.contains(k)) {
				ans = "NO";
				break;
			}
			hs.add(k);
//			System.out.println(k + " " + n + " " + m);
			n = n / m;
		}
		return ans;
	}

	public static void main(String[] args) {

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

		System.out.println(check(n, m));
	}

}
