using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		var list = PrimeFactors(B);
		list.Sort((x,y)=>x.CompareTo(y));
		var list2 = new List<long[]>();
		long ta = -1;
		int ct = -1;
		for(var i=0;i<list.Count;i++){
			if(list[i]==ta){
				list2[ct][1]++;
			} else {
				list2.Add(new long[2]{list[i],1});
				ta = list[i];
				ct++;
			}
		}
		long min = -1;
		for(var i=0;i<list2.Count;i++){
			long c1 = list2[i][0];
			long ctb = 0;
			while(true){
				ctb += N/c1;
				if(N/c1<list2[i][0]){
					break;
				}
				c1 *= list2[i][0];
			}
			if(min==-1){
				min = ctb/list2[i][1];
			} else {
				min = Math.Min(min,ctb/list2[i][1]);
			}
		}
		Console.WriteLine(min);
	}

	public static List<long> PrimeFactors(long n){
		long i = 2;
		long tmp = n;
		var list = new List<long>();
		while(i*i<=n){
			if(tmp%i==0){
				tmp /= i;
				list.Add(i);
			} else {
				i++;
			}
		}
		if(tmp != 1){
			list.Add(tmp);
		}
		return list;
	}
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int64;
using N = System.Int64;
using C = System.Int32;
namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			var n = rl;
			var b = rl;
			var P = new List<long[]>();
			for (long i = 2; i * i <= b; i++) {
				var cnt = 0;
				while (b % i == 0) { b /= i; cnt++; }
				if (cnt != 0) P.Add(new long[] { i, cnt });
			}
			if (b != 1) P.Add(new long[] { b, 1 });
			var min = INF;
			foreach (var p in P) {
				var v = ord(n, p[0]) / p[1];
				min = Min(min, v);
			}
			Console.WriteLine(min);
		}
		long ord(long n, long p) {
			var ret = 0L;
			while (n > 0) {
				n /= p;
				ret += n;
			}
			return ret;
		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < a.Length; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		//Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion

#region Set
/// <summary>
/// 要素の追加、削除、検索、取得が可能な集合を表します．
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します．</typeparam>
/// <remarks>内部的にはAVL木によって実装されています．</remarks>
public class Set<T> {
	Node root;
	readonly IComparer<T> comparer;
	readonly Node nil;
	/// <summary>
	/// 多重集合かどうかを表します．
	/// </summary>
	public bool IsMultiSet { get; set; }
	public Set(IComparer<T> comparer) {
		nil = new Node(default(T));
		root = nil;
		this.comparer = comparer;
	}
	public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison)) { }
	public Set() : this(Comparer<T>.Default) { }
	/// <summary>
	/// 要素をコレクションに追加します．
	/// </summary>
	/// <remarks>この操作は計算量 O(log N) で実行されます．</remarks>
	public bool Add(T v) {
		return insert(ref root, v);
	}
	/// <summary>
	/// v が存在するならコレクションから削除します．
	/// </summary>
	/// <remarks>この操作は計算量 O(log N) で実行されます．</remarks>
	public bool Remove(T v) {
		return remove(ref root, v);
	}
	/// <summary>
	/// 0-indexed で index 番目の要素をコレクションから取得します．．
	/// </summary>
	/// <remarks>この操作は計算量 O(log N) で実行されます．</remarks>
	public T this[int index] { get { return find(root, index); } }
	public int Count { get { return root.Count; } }
	public void RemoveAt(int k) {
		if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException();
		removeAt(ref root, k);
	}
	/// <summary>
	/// このコレクションに含まれる要素を昇順に並べて返します．
	/// </summary>
	/// <remarks>この操作は計算量 O(N) で実行されます．</remarks>
	public T[] Items {
		get {
			var ret = new T[root.Count];
			var k = 0;
			walk(root, ret, ref k);
			return ret;
		}
	}
	void walk(Node t, T[] a, ref int k) {
		if (t.Count == 0) return;
		walk(t.lst, a, ref k);
		a[k++] = t.Key;
		walk(t.rst, a, ref k);
	}

	bool insert(ref Node t, T key) {
		if (t.Count == 0) { t = new Node(key); t.lst = t.rst = nil; t.Update(); return true; }
		var cmp = comparer.Compare(t.Key, key);
		bool res;
		if (cmp > 0)
			res = insert(ref t.lst, key);
		else if (cmp == 0) {
			if (IsMultiSet) res = insert(ref t.lst, key);
			else return false;
		}
		else res = insert(ref t.rst, key);
		balance(ref t);
		return res;
	}
	bool remove(ref Node t, T key) {
		if (t.Count == 0) return false;
		var cmp = comparer.Compare(key, t.Key);
		bool ret;
		if (cmp < 0) ret = remove(ref t.lst, key);
		else if (cmp > 0) ret = remove(ref t.rst, key);
		else {
			ret = true;
			var k = t.lst.Count;
			if (k == 0) { t = t.rst; return true; }
			if (t.rst.Count == 0) { t = t.lst; return true; }

			t.Key = find(t.lst, k - 1);
			removeAt(ref t.lst, k - 1);
		}
		balance(ref t);
		return ret;
	}
	void removeAt(ref Node t, int k) {
		var cnt = t.lst.Count;
		if (cnt < k) removeAt(ref t.rst, k - cnt - 1);
		else if (cnt > k) removeAt(ref t.lst, k);
		else {
			if (cnt == 0) { t = t.rst; return; }
			if (t.rst.Count == 0) { t = t.lst; return; }

			t.Key = find(t.lst, k - 1);
			removeAt(ref t.lst, k - 1);
		}
		balance(ref t);
	}
	void balance(ref Node t) {
		var balance = t.lst.Height - t.rst.Height;
		if (balance == -2) {
			if (t.rst.lst.Height - t.rst.rst.Height > 0) { rotR(ref t.rst); }
			rotL(ref t);
		}
		else if (balance == 2) {
			if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst);
			rotR(ref t);
		}
		else t.Update();
	}

	T find(Node t, int k) {
		if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException();
		for (; ; )
		{
			if (k == t.lst.Count) return t.Key;
			else if (k < t.lst.Count) t = t.lst;
			else { k -= t.lst.Count + 1; t = t.rst; }
		}
	}
	/// <summary>
	/// コレクションに含まれる要素であって、 v 以上の最小の要素の番号を返します。
	/// </summary>
	/// <remarks>この操作は計算量 O(log N) で実行されます．</remarks>
	public int LowerBound(T v) {
		var k = 0;
		var t = root;
		for (; ; )
		{
			if (t.Count == 0) return k;
			if (comparer.Compare(v, t.Key) <= 0) t = t.lst;
			else { k += t.lst.Count + 1; t = t.rst; }
		}
	}
	/// <summary>
	/// コレクションに含まれる要素であって、 v より真に大きい、最小の要素の番号を返します。
	/// </summary>
	/// <remarks>この操作は計算量 O(log N) で実行されます．</remarks>
	public int UpperBound(T v) {
		var k = 0;
		var t = root;
		for (; ; )
		{
			if (t.Count == 0) return k;
			if (comparer.Compare(t.Key, v) <= 0) { k += t.lst.Count + 1; t = t.rst; }
			else t = t.lst;
		}
	}

	void rotR(ref Node t) {
		var l = t.lst;
		t.lst = l.rst;
		l.rst = t;
		t.Update();
		l.Update();
		t = l;
	}
	void rotL(ref Node t) {
		var r = t.rst;
		t.rst = r.lst;
		r.lst = t;
		t.Update();
		r.Update();
		t = r;
	}

	class Node {
		public Node(T key) {
			Key = key;
		}
		public int Count { get; private set; }
		public sbyte Height { get; private set; }
		public T Key { get; set; }
		public Node lst, rst;
		public void Update() {
			Count = 1 + lst.Count + rst.Count;
			Height = (sbyte)(1 + Math.Max(lst.Height, rst.Height));
		}
		public override string ToString() {
			return string.Format("Count = {0}, Key = {1}", Count, Key);
		}
	}
}
#endregion


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            long n = ReadLong();
            long b = ReadLong();

            long ans = long.MaxValue;

            for (long i = 2; i * i <= b; i++)
            {
                if (b % i == 0)
                {
                    long t = Calc(n, i, ref b);

                    ans = Math.Min(ans, t);
                }
            }
            if (b > 1)
            {
                long t = Calc(n, b, ref b);

                ans = Math.Min(ans, t);
            }

            Writer.WriteLine(ans);
        }

        private static long Calc(long n, long i, ref long b)
        {
            long p = 0;
            while (b % i == 0)
            {
                b /= i;
                p++;
            }

            long d = n;
            long t = 0;
            while (d > 0)
            {
                d /= i;
                t += d;
            }
            t /= p;
            return t;
        }

        public static void Solve()
        {
#if DEBUG
            var sw = Stopwatch.StartNew();
#endif

            SolveCase();

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                // Writer.WriteLine("Case {0}:", i + 1);
                // Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

#if DEBUG
            sw.Stop();
            Console.WriteLine($"{sw.ElapsedMilliseconds} ms");
#endif
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            // Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            writer.WriteLine(valueToWrite.ToString("F8"));
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        ulong n,b;

        ulong min = ulong.MaxValue;

        ulong compPow(ulong prime)
        {
            ulong rez = 0;

            ulong times = 0;
            ulong pow = 1;
            ulong powv = (ulong)prime;

            while(true)
            {
                times = n / powv;
                pow++;

                rez += times;

                if (times == 0)
                    break;

                if (n / powv / prime < 1)
                    break;

                powv *= (ulong)prime;
            }

            return rez;
        }

        public void Solve()
        {
            n = ulong.Parse(ioHelper.ReadNextToken());
            b = ulong.Parse(ioHelper.ReadNextToken());

            ulong prime = 2;
            ulong origB = b;

            while(prime * prime <= b)
            {
                ulong powInB = 0;

                while(b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                if (powInB == 0)
                { prime++;continue; }

                var powInFact = compPow(prime);

                var times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            if(b>1)
            {
                prime = b;

                ulong powInB = 0;

                while (b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                ulong powInFact = compPow(prime);

                ulong times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            ioHelper.WriteLine(min.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    Scanner sc = new Scanner();
    //

    public void Solve()
    {
        long n, b;
        sc.Make(out n, out b);
        var f = Factorize(b);
        var min = long.MaxValue;
        foreach (var p in f)
        {
            var ct = 0L;
            var a = n;
            while (a!=0)
            {
                a /= p.Key;
                ct += a;
            }
            chmin(ref min, ct / p.Value);
        }
        WriteLine(min);
    }

    public static Dictionary<long, int> Factorize(long num)
    {
        var dic = new Dictionary<long, int>();
        for (var i = 2L; i * i <= num; i++)
        {
            var ct = 0;
            while (num % i == 0)
            {
                ct++;
                num /= i;
            }
            if (ct != 0) dic[i] = ct;
        }
        if (num != 1) dic[num] = 1;
        return dic;
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve();
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		WriteLine(Solve());
		Out.Flush();
	}
	long Solve()
	{
		var I = GL;
		long n = I[0], b = I[1];
		var ps = GetPrimes(2000000);
		var f = Factorize(b, ps);
		var ans = long.MaxValue;
		foreach (var p in f.Keys)
		{
			var c = 0L;
			var m = n / p;
			while (m > 0) { c += m; m /= p; }
			ans = Min(ans, c / f[p]);
		}
		return ans;
	}
	public static Dictionary<long, int> Factorize(long n, List<int> primes)
	{
		var d = new Dictionary<long, int>();
		for (var j = 0; j < primes.Count; j++)
		{
			var i = primes[j];
			if (i * i > n) break;
			if (n % i == 0)
			{
				d.Add(i, 0);
				while (n % i == 0) { n /= i; d[i]++; }
			}
		}
		if (n > 1) d.Add(n, 1);
		return d;
	}
	public static List<int> GetPrimes(int n)
	{
		if (n < 3) n = 3;
		var m = (n - 1) >> 1;
		var primes = new List<int>((int)(n / Math.Log(n)));
		primes.Add(2);
		var composites = new bool[m];
		composites[0] = false;
		for (var p = 0; p < m; p++)
		{
			if (!composites[p])
			{
				var pnum = 2 * p + 3;
				primes.Add(pnum);
				for (var k = 3 * p + 3; k < m; k += pnum) composites[k] = true;
			}
		}
		return primes;
	}
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Trailing_Loves
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static IEnumerable<long> G()
        {
            yield return 2L;
            for (long i = 3;; i += 2)
            {
                yield return i;
            }
        }

        private static long Solve(string[] args)
        {
            long n = Next();
            long b = Next();

            var list = new List<long>();
            foreach (long i in G())
            {
                if (i*i > b)
                    break;
                while (b%i == 0)
                {
                    b /= i;
                    list.Add(i);
                }
            }
            if (b != 1)
                list.Add(b);

            long ans = long.MaxValue;
            foreach (var p in list.GroupBy(t => t).Select(t => new {t.Key, cnt = t.Count()}))
            {
                ans = Math.Min(ans, Count(n, p.Key)/p.cnt);
            }

            return ans;
        }

        private static long Count(long n, long max)
        {
            long ans = 0;
            for (long i = max;;)
            {
                ans += n/i;
                if (n/max >= i)
                    i *= max;
                else
                    break;
            }
            return ans;
        }

        private static long Next()
        {
            int c;
            long res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


/*
csc -debug C.cs && mono --debug C.exe <<< "6 9"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class HelloWorld {
    public static void SolveCodeForces() {
        var n = cin.NextUlong();
        var b = cin.NextUlong();

        var ans = ulong.MaxValue;
        foreach (var ppow in GetPrimeDivisors(b)) {
            ans = Math.Min(ans, FF( n, ppow[0], ppow[1] ));
        }
        System.Console.WriteLine(ans);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static IEnumerable<ulong[]> GetPrimeDivisors(ulong n) {
        for (var p = 2ul; p * p <= n; p++)
            if (n % p == 0) {

                n /= p;
                var pow = 1ul;
                while (n % p == 0) { pow++; n /= p; }

                yield return new[] { p, pow };
            }
        if (n > 1)
            yield return new[] { n, 1ul };
    }

    static ulong F(ulong n, ulong p) {
        if (n == 1) return 0;

        var ans = 0ul;

        var i = 1ul;
        var pow = p;
        while (pow <= n) {
            ans += n / pow;
            i++;
            pow *= p;
        }

        return ans;
    }

    static ulong FF(ulong n, ulong p, ulong pow) {
        return F(n, p) / pow;
    }

    static void TestF() {
        for (var n = 2ul; n <= 4; n++) {
            System.Console.WriteLine(n);

            var fact = 1ul;
            for (var i = 1ul; i <= n; i++)
                fact *= i;

            for (var prime = 2ul; prime <= fact; prime++) {
                if (!Brute_IsPrime(prime)) continue;

                for (var pow = 1ul; Math.Pow(prime, pow) <= fact; pow++) {

                    // System.Console.WriteLine(new { n, prime, pow });

                    var actual = FF(n, prime, pow);

                    var apow = (ulong)Math.Pow(prime, pow);
                    var expected = 0ul;
                    var rem = fact;
                    while (rem % apow == 0) {
                        expected++;
                        rem /= apow;
                    }

                    if (expected != actual) {
                        System.Console.WriteLine("Err");
                        System.Console.WriteLine(new { n, fact, prime, pow, actual, expected });
                        return;
                    }

                }
            }
        }
    }

    public static ulong Pow(ulong x, ulong exp) {
        ulong ret = 1ul;
        while (exp > 0) {
            if (exp % 2 == 1) ret = ret * x;
            x = x * x;
            exp /= 2;
        }
        return ret;
    }

    static bool Brute_IsPrime(ulong a) {
        if (a <= 1ul) return false;
        for (var i = 2ul; i * i <= a; i++)
            if (a % i == 0)
                return false;
        return true;
    }

    static public void Main () {
        SolveCodeForces();
        // TestF();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            writer.WriteLine(valueToWrite.ToString("F8"));
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        ulong n,b;

        ulong min = long.MaxValue;

        ulong compPow(ulong prime)
        {
            ulong rez = 0;

            ulong times = 0;
            ulong pow = 1;
            ulong powv = (ulong)prime;

            while(true)
            {
                times = n / powv;
                pow++;
                powv *= (ulong)prime;

                rez += times;

                if (times == 0)
                    break;
            }

            return rez;
        }

        public void Solve()
        {
            n = ulong.Parse(ioHelper.ReadNextToken());
            b = ulong.Parse(ioHelper.ReadNextToken());

            ulong prime = 2;
            ulong origB = b;

            while(prime * prime <= b)
            {
                ulong powInB = 0;

                while(b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                if (powInB == 0)
                { prime++;continue; }

                var powInFact = compPow(prime);

                var times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            if(b>1)
            {
                prime = b;

                ulong powInB = 0;

                while (b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                ulong powInFact = compPow(prime);

                ulong times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            ioHelper.WriteLine(min.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            long current = factor.Key;
            long count = 0;
            double limit = Sqrt(nb[0] + 100);
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (((double)current * (double)factor.Key) >= nb[0] + 114514) break;
                current *= factor.Key;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        if(n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 100)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		var list = PrimeFactors(B);
		list.Sort((x,y)=>x.CompareTo(y));
		var list2 = new List<long[]>();
		long ta = -1;
		int ct = -1;
		for(var i=0;i<list.Count;i++){
			if(list[i]==ta){
				list2[ct][1]++;
			} else {
				list2.Add(new long[2]{list[i],1});
				ta = list[i];
				ct++;
			}
		}
		long min = -1;
		for(var i=0;i<list2.Count;i++){
			long c1 = list2[i][0];
			long ctb = 0;
			while(true){
				ctb += N/c1;
				c1 *= list2[i][0];
				if(c1>N){
					break;
				}
			}
			if(min==-1){
				min = ctb/list2[i][1];
			} else {
				min = Math.Min(min,ctb/list2[i][1]);
			}
		}
		Console.WriteLine(min);
	}

	public static List<long> PrimeFactors(long n){
		long i = 2;
		long tmp = n;
		var list = new List<long>();
		while(i*i<=n){
			if(tmp%i==0){
				tmp /= i;
				list.Add(i);
			} else {
				i++;
			}
		}
		if(tmp != 1){
			list.Add(tmp);
		}
		return list;
	}
}


using System;
using System.Collections.Generic;

namespace CSharp
{
    class _1114C
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            long n = long.Parse(tokens[0]);
            long b = long.Parse(tokens[1]);

            var factors = new Dictionary<long, long>();

            for (int i = 2; i <= 1000000; i++)
            {
                long count = 0;

                while (b % i == 0)
                {
                    b /= i;
                    count++;
                }

                if (count > 0)
                {
                    factors.Add(i, count);
                }
            }

            if (b > 1)
            {
                factors.Add(b, 1);
            }

            long result = int.MaxValue;

            foreach (var f in factors)
            {
                long x = n;
                long count = 0;

                while (x >= f.Key)
                {
                    x /= f.Key;
                    count += x;
                }

                result = Math.Min(result, count / f.Value);
            }

            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            writer.WriteLine(valueToWrite.ToString("F8"));
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        long n,b;

        long min = long.MaxValue;

        long compPow(long prime)
        {
            long rez = 0;

            long times = 0;
            long pow = 1;
            long powv = prime;

            while(true)
            {
                times = n / powv;
                pow++;
                powv *= prime;

                rez += times;

                if (times == 0)
                    break;
            }

            return rez;
        }

        public void Solve()
        {
            n = long.Parse(ioHelper.ReadNextToken());
            b = long.Parse(ioHelper.ReadNextToken());

            long prime = 2;
            long origB = b;

            while(prime * prime <= b)
            {
                long powInB = 0;

                while(b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                if (powInB == 0)
                { prime++;continue; }

                long powInFact = compPow(prime);

                long times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            if(b>1)
            {
                prime = b;

                long powInB = 0;

                while (b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                long powInFact = compPow(prime);

                long times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            ioHelper.WriteLine(min.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            var current = factor.Key;
            long count = 0;
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (current <= int.MaxValue) current *= factor.Key;
                else break;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        if(n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 1)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            long current = factor.Key;
            long count = 0;
            double rimit = Sqrt(nb[0] + 100);
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (current <= rimit) current *= factor.Key;
                else break;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        if(n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 1)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            var current = factor.Key;
            long count = 0;
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (current <= 1e8) current *= factor.Key;
                else break;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        if(n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 1)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            long current = factor.Key;
            long count = 0;
            double rimit = Sqrt(nb[0] + 100);
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (((double)current * (double)factor.Key) <= nb[0] + 114514) current *= factor.Key;
                else break;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        if(n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 1)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<long, long>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        var N = cin.nextlong;
        var B = cin.nextlong;

        var H = new Map<long, int>();
        var T = B;
        for (long i = 2; i <= T / i; i++)
        {
            while (T % i == 0)
            {
                T /= i;
                H[i]++;
            }
        }
        if (T != 1)
        {
            H[T]++;
        }
        //var G = new Map<long, int>();
        //T = N;
        //for (long i = 2; i * i <= T; i++)
        //{
        //    while (T % i == 0)
        //    {
        //        T /= i;
        //        G[i]++;
        //    }
        //}
        //if (T != 1)
        //{
        //    G[T]++;
        //}

        long ans = long.MaxValue;
        //foreach (var v in H)
        //{
        //    var P = 0L;
        //    if(G.ContainsKey(v.Key))
        //    {
        //        P = G[v.Key];
        //        WriteLine(v.Key + " " + P);
        //    }
        //    chmin(ref ans, P / v.Value);
        //}

        foreach (var v in H)
        {
            var key = v.Key;
            var P = N / key;

            while (N / key >= key)
            {
                key *= key;
                P += N / key;
            }
            var value = v.Value;

            var c = P / value;

            //WriteLine(P + " " + value);
            chmin(ref ans, c);
        }
        WriteLine(ans);
    }

}

class Map<TKey, TValue> : Dictionary<TKey, TValue>
{
    public new TValue this[TKey key]
    {
        get
        {
            if (!ContainsKey(key))
            {
                base[key] = default(TValue);
            }
            return base[key];
        }
        set
        {
            base[key] = value;
        }
    }
}
static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            writer.WriteLine(valueToWrite.ToString("F8"));
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        long n,b;

        long min = long.MaxValue;

        long compPow(long prime)
        {
            long rez = 0;

            long times = 0;
            long pow = 1;
            long powv = prime;

            while(true)
            {
                times = n / powv;
                pow++;
                powv *= prime;

                rez += times;

                if (times == 0)
                    break;
            }

            return rez;
        }

        public void Solve()
        {
            n = long.Parse(ioHelper.ReadNextToken());
            b = long.Parse(ioHelper.ReadNextToken());

            long prime = 2;
            long origB = b;

            while(prime * prime <= b)
            {
                long powInB = 0;

                while(b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                if (powInB == 0)
                    continue;

                long powInFact = compPow(prime);

                long times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            if(b>1)
            {
                prime = b;

                long powInB = 0;

                while (b % prime == 0)
                {
                    powInB++;
                    b /= prime;
                }

                long powInFact = compPow(prime);

                long times = powInFact / powInB;

                if (times < min)
                    min = times;

                prime++;
            }

            ioHelper.WriteLine(min.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            var current = factor.Key;
            long count = 0;
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (current <= 1e8) current *= factor.Key;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        if(n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 1)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}


using System;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] akk = new int[3];
            for (int i = 0; i < 3; i++)
            {
                switch (input[i])
                {
                    case "C": akk[i] = 0; break;
                    case "C#": akk[i] = 1; break;
                    case "D": akk[i] = 2; break;
                    case "D#": akk[i] = 3; break;
                    case "E": akk[i] = 4; break;
                    case "F": akk[i] = 5; break;
                    case "F#": akk[i] = 6; break;
                    case "G": akk[i] = 7; break;
                    case "G#": akk[i] = 8; break;
                    case "A": akk[i] = 9; break;
                    case "B": akk[i] = 10; break;
                    case "H": akk[i] = 11; break;
                    default: akk[i] = -1; break;
                }
            }
            int type = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int k = 3 - (i + j);
                    if (d(akk[i], akk[j]) == 7)
                    {
                        if ((d(akk[i], akk[k]) == 4) & (d(akk[k], akk[j]) == 3)) { type = 1; break; }
                        else if ((d(akk[i], akk[k]) == 3) & (d(akk[k], akk[j]) == 4)) type = -1;
                    }
                }
            }
            switch (type)
            {
                case 1: Console.Write("major"); break;
                case -1: Console.Write("minor"); break;
                default: Console.Write("strange"); break;
            }
        }
        static int d(int a1, int a2)
        {
            if (a2 >= a1) return a2 - a1; else return 12 - (a1 - a2);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    class Program
    {
        //enum notes { C, C#, D, D#, E, F, F#, G, G#, A, B, H};
        static void Main(string[] args)
        {
            string[] t = Console.ReadLine().Split(' ');
            int[] notes = new int[3];
            for(int i = 0; i < 3; i++)
            {
                switch (t[i])
                {
                    case "C": notes[i] = 1;
                        break;
                    case "C#": notes[i] = 2;
                        break;
                    case "D": notes[i] = 3;
                        break;
                    case "D#": notes[i] = 4;
                        break;
                    case "E": notes[i] = 5;
                        break;
                    case "F": notes[i] = 6;
                        break;
                    case "F#": notes[i] = 7;
                        break;
                    case "G": notes[i] = 8;
                        break;
                    case "G#": notes[i] = 9;
                        break;
                    case "A": notes[i] = 10;
                        break;
                    case "B": notes[i] = 11;
                        break;
                    case "H": notes[i] = 12;
                        break;
                }
            }
            int[,] map = new int[3, 3];
            int first = 0;
            int second = 0;
            int third = 0;
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                {
                    if (notes[i] > notes[j])
                        map[i, j] = 12 - notes[i] + notes[j];
                    else
                        map[i, j] = notes[j] - notes[i];
                    if (map[i, j] == 7)
                    {
                        first = i;
                        third = j;
                        if (i != 0 && j != 0) second = 0;
                        if (i != 1 && j != 1) second = 1;
                        if (i != 2 && j != 2) second = 2;
                    }
                }
            if (first != third)
            {
                if (map[first, second] == 4)
                    Console.WriteLine("major");
                else if (map[first, second] == 3)
                    Console.WriteLine("minor");
                else Console.WriteLine("strange");
            }
            else
                Console.WriteLine("strange");
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;

namespace Codeforces
{
    class TaskA
    {
        static void Main()
        {
            var all = new List<string>(new string[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" });
            var input = Console.ReadLine().Trim().Split(' ');
            var answ = "strange";
            var x = input[2];
            var y = input[0];
            var z = input[1];
            if ((all.IndexOf(x) - all.IndexOf(y) == 7) || (all.IndexOf(x) - all.IndexOf(y) == -5))
            {
                if ((all.IndexOf(z) - all.IndexOf(y) == 4) || (all.IndexOf(z) - all.IndexOf(y) == -8))
                {
                    answ = "major";
                }
                else if ((all.IndexOf(z) - all.IndexOf(y) == 3) || (all.IndexOf(z) - all.IndexOf(y) == -9))
                {
                    answ = "minor";
                }
            }
            x = input[2];
            y = input[1];
            z = input[0];
            if ((all.IndexOf(x) - all.IndexOf(y) == 7) || (all.IndexOf(x) - all.IndexOf(y) == -5))
            {
                if ((all.IndexOf(z) - all.IndexOf(y) == 4) || (all.IndexOf(z) - all.IndexOf(y) == -8))
                {
                    answ = "major";
                }
                else if ((all.IndexOf(z) - all.IndexOf(y) == 3) || (all.IndexOf(z) - all.IndexOf(y) == -9))
                {
                    answ = "minor";
                }
            }
            x = input[1];
            y = input[2];
            z = input[0];
            if ((all.IndexOf(x) - all.IndexOf(y) == 7) || (all.IndexOf(x) - all.IndexOf(y) == -5))
            {
                if ((all.IndexOf(z) - all.IndexOf(y) == 4) || (all.IndexOf(z) - all.IndexOf(y) == -8))
                {
                    answ = "major";
                }
                else if ((all.IndexOf(z) - all.IndexOf(y) == 3) || (all.IndexOf(z) - all.IndexOf(y) == -9))
                {
                    answ = "minor";
                }
            }
            x = input[1];
            y = input[0];
            z = input[2];
            if ((all.IndexOf(x) - all.IndexOf(y) == 7) || (all.IndexOf(x) - all.IndexOf(y) == -5))
            {
                if ((all.IndexOf(z) - all.IndexOf(y) == 4) || (all.IndexOf(z) - all.IndexOf(y) == -8))
                {
                    answ = "major";
                }
                else if ((all.IndexOf(z) - all.IndexOf(y) == 3) || (all.IndexOf(z) - all.IndexOf(y) == -9))
                {
                    answ = "minor";
                }
            }
            x = input[0];
            y = input[1];
            z = input[2];
            if ((all.IndexOf(x) - all.IndexOf(y) == 7) || (all.IndexOf(x) - all.IndexOf(y) == -5))
            {
                if ((all.IndexOf(z) - all.IndexOf(y) == 4) || (all.IndexOf(z) - all.IndexOf(y) == -8))
                {
                    answ = "major";
                }
                else if ((all.IndexOf(z) - all.IndexOf(y) == 3) || (all.IndexOf(z) - all.IndexOf(y) == -9))
                {
                    answ = "minor";
                }
            }
            x = input[0];
            y = input[2];
            z = input[1];
            if ((all.IndexOf(x) - all.IndexOf(y) == 7) || (all.IndexOf(x) - all.IndexOf(y) == -5))
            {
                if ((all.IndexOf(z) - all.IndexOf(y) == 4) || (all.IndexOf(z) - all.IndexOf(y) == -8))
                {
                    answ = "major";
                }
                else if ((all.IndexOf(z) - all.IndexOf(y) == 3) || (all.IndexOf(z) - all.IndexOf(y) == -9))
                {
                    answ = "minor";
                }
            }

            Console.WriteLine(answ);
        }
    }
}


using System;

namespace Task1 {
    internal class Program {
        private static void Main(string[] args) {
            string s = Console.ReadLine();
            string[] ss = s.Split(' ');
//            C, C#, D, D#, E, F, F#, G, G#, A, B, H
            int x = Get(ss[0]);
            int y = Get(ss[1]);
            int z = Get(ss[2]);
            string result;
            if (Check(x, y, z, out result)) {
                Console.WriteLine(result);
                return;
            }
            if (Check(x, z, y, out result)) {
                Console.WriteLine(result);
                return;
            }
            if (Check(y, x, z, out result)) {
                Console.WriteLine(result);
                return;
            }
            if (Check(y, z, x, out result)) {
                Console.WriteLine(result);
                return;
            }
            if (Check(z, x, y, out result)) {
                Console.WriteLine(result);
                return;
            }
            if (Check(z, y, x, out result)) {
                Console.WriteLine(result);
                return;
            }
            Console.WriteLine("strange");
        }

        private static bool Check(int x, int y, int z, out string result) {
            while (x > y) {
                y += 12;
            }
            while (y > z) {
                z += 12;
            }
            int delta1 = (y - x);
            int delta2 = (z - y);
            if (delta1 == 3 && delta2 == 4) {
                result = "minor";
                return true;
            }
            if (delta1 == 4 && delta2 == 3) {
                result = "major";
                return true;
            }
            result = "";
            return false;
        }

        private static int Get(string s) {
            string[] temp = new string[] {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
            for (int i = 0; i < temp.Length; i++) {
                if (temp[i].Equals(s))
                    return i;
            }
            return 0;
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace a1cs
{
    class Program
    {

        static int Gt(string s)
        {
            switch (s)
            {
                case "C":
                    {
                        return 0;
                        break;
                    }
                case "C#":
                    {
                        return 1;
                        break;
                    }
                case "D":
                    {
                        return 2;
                        break;
                    }
                case "D#":
                    {
                        return 3;
                        break;
                    }
                case "E":
                    {
                        return 4;
                        break;
                    }
                case "F":
                    {
                        return 5;
                        break;
                    }
                case "F#":
                    {
                        return 6;
                        break;
                    }
                case "G":
                    {
                        return 7;
                        break;
                    }
                case "G#":
                    {
                        return 8;
                        break;
                    }
                case "A":
                    {
                        return 9;
                        break;
                    }
                case "B":
                    {
                        return 10;
                        break;
                    }
                default:
                    {
                        return 11;
                    }
            }
        }

        static void Main()
        {
            //TextReader fin = File.OpenText("input.txt");
            //TextWriter fout = File.CreateText("output.txt");
            string[] ss = Console.ReadLine().Split();
            int a = Gt(ss[0]);
            int b = Gt(ss[1]);
            int c = Gt(ss[2]);
            int d;
            if (a > b)
            {
                d = a;
                a = b;
                b = d;
            }
            if (a > c)
            {
                d = a;
                a = c;
                c = d;
            }
            if (b > c)
            {
                d = b;
                b = c;
                c = d;
            }
            if ((b - a == 3) && (c - b == 4)) Console.WriteLine("minor");
            else if ((c - a == 3) && (b + 12 - c  == 4)) Console.WriteLine("minor");
            else if ((a + 12 - b == 3) && (c - a == 4)) Console.WriteLine("minor");
            else if ((c - b == 3) && (a + 12 - c == 4)) Console.WriteLine("minor");
            else if ((a + 12 - c == 3) && (b - a == 4)) Console.WriteLine("minor");
            else if ((b + 12 - c == 3) && (a + 12 - b == 4)) Console.WriteLine("minor");
            else if ((b - a == 4) && (c - b == 3)) Console.WriteLine("major");
            else if ((c - a == 4) && (b + 12 - c  == 3)) Console.WriteLine("major");
            else if ((a + 12 - b == 4) && (c - a == 3)) Console.WriteLine("major");
            else if ((c - b == 4) && (a + 12 - c == 3)) Console.WriteLine("major");
            else if ((a + 12 - c == 4) && (b - a == 3)) Console.WriteLine("major");
            else if ((b + 12 - c == 4) && (a + 12 - b == 3)) Console.WriteLine("major");
            else Console.WriteLine("strange");
            //fin.Close();
            //fout.Close();
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;

public class CF_Chord
{
    static string[] N = new string[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

    public static int dist(string a, string b)
    {
        int pos1 = Array.IndexOf(N, a);
        int pos2 = Array.IndexOf(N, b);
        int d = pos2 - pos1;
        if (d < 0) d = 12 + d;
        return d;
    }

    public static string chord(string a, string b, string c)
    {
        int d1 = dist(a, b);
        int d2 = dist(b, c);

        string ans = "strange";
        if (d1 == 4 && d2 == 3) ans = "major";
        else if (d1 == 3 && d2 == 4) ans = "minor";
        return ans;
    }

    public static void Main(string[] args)
    {
        string[] notes = Console.ReadLine().Split();
        int n = notes.Length;
        string a = notes[0];
        string b = notes[1];
        string c = notes[2];
        int d1 = dist(notes[0], notes[1]);
        int d2 = dist(notes[1], notes[2]);

        string ans = chord(a, b, c);
        if (ans == "strange") ans = chord(a, c, b);
        if (ans == "strange") ans = chord(b, a, c);
        if (ans == "strange") ans = chord(b, c, a);
        if (ans == "strange") ans = chord(c, a, b);
        if (ans == "strange") ans = chord(c, b, a);

        Console.WriteLine(ans);
        Console.ReadLine();
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace CF
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			{
				//using (var sw = new StreamWriter("output.txt")) {
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		private List<string> notes = new List<string>() { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

		public void Solve(InputReader sr, TextWriter sw)
		{
			var str = sr.NextSplitStrings();
			var x = str[0];
			var y = str[1];
			var z = str[2];
			for (var i = 0; i < 3; i++) {
				for (var j = 0; j < 3; j++) {
					if (j != i) {
						for (var k = 0; k < 3; k++) {
							if (k != i && k != j) {
								if (IsMajor(str[i], str[j], str[k])) {
									sw.WriteLine("major");
									return;
								}
								if (IsMinor(str[i], str[j], str[k]))
								{
									sw.WriteLine("minor");
									return;
								}
							}
						}
					}
				}
			}

			sw.WriteLine("strange");
		}

		private bool IsMajor(string x, string y, string z)
		{
			var indxX = notes.IndexOf(x);
			var indxY = notes.IndexOf(y);
			var indxZ = notes.IndexOf(z);
			var d1 = 0;
			if (indxX <= indxY) {
				d1 = indxY - indxX;
			}
			else {
				d1 = notes.Count - indxX  + indxY;
			}
			var d2 = 0;
			if (indxY <= indxZ) {
				d2 = indxZ - indxY;
			}
			else {
				d2 = notes.Count - indxY + indxZ;
			}

			return d1 == 4 && d2 == 3;
		}

		private bool IsMinor(string x, string y, string z)
		{
			var indxX = notes.IndexOf(x);
			var indxY = notes.IndexOf(y);
			var indxZ = notes.IndexOf(z);
			var d1 = 0;
			if (indxX <= indxY)
			{
				d1 = indxY - indxX;
			}
			else
			{
				d1 = notes.Count - indxX + indxY;
			}
			var d2 = 0;
			if (indxY <= indxZ)
			{
				d2 = indxZ - indxY;
			}
			else
			{
				d2 = notes.Count - indxY + indxZ;
			}

			return d1 == 3 && d2 == 4;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
										.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
										.Select(s => func(s, CultureInfo.InvariantCulture))
										.ToArray();
	}

	public int[] ReadArrayOfInt32()
	{
		return ReadArray(Int32.Parse);
	}

	public long[] ReadArrayOfInt64()
	{
		return ReadArray(Int64.Parse);
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
										str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
																		.Select(s => func(s, CultureInfo.InvariantCulture))
																		.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose)
		{
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cs_console
{
    class _73_2_B
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(test());
        }
        static string test()
        {
            string[] ss = Console.ReadLine().Split(' ');
            int[] c = new int[3];
            for (int i = 0; i < 3; i++)
            {
                c[i] = ch(ss[i]);
            }
            string[] ans = { "major", "minor", "strange" };

            Array.Sort(c);
            if (c[0] == c[1] - 4 && c[1] == c[2] - 3)
            {
                return ans[0];
            }
            if (c[0] == c[1] - 3 && c[1] == c[2] - 4)
            {
                return ans[1];
            }

            c[0] += 12;
            Array.Sort(c);
            if (c[0] == c[1] - 4 && c[1] == c[2] - 3)
            {
                return ans[0];
            }
            if (c[0] == c[1] - 3 && c[1] == c[2] - 4)
            {
                return ans[1];
            }

            c[0] += 12;
            Array.Sort(c);
            if (c[0] == c[1] - 4 && c[1] == c[2] - 3)
            {
                return ans[0];
            }
            if (c[0] == c[1] - 3 && c[1] == c[2] - 4)
            {
                return ans[1];
            }

            return ans[2];
        }

        private static int ch(string p)
        {
            string[] keys = new string[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };
            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i] == p)
                    return i;
            }
            return -1;
        }

    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prA {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif
        static bool Try(int n1, int n2, int n3) {
            int p1 = (n2 - n1 + 12) % 12;
            int p2 = (n3 - n2 + 12) % 12;
            if (p1==4 && p2==3) {
                writer.Write("major");
                return true;
            }
            if(p1 == 3 && p2 == 4) {
                writer.Write("minor");
                return true;
            }
            return false;
        }

        static void Main(string[] args) {
            string[] notes = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
            string[] a = reader.ReadLine().Split(' ');
            int n1 = Array.IndexOf(notes, a[0]);
            int n2 = Array.IndexOf(notes, a[1]);
            int n3 = Array.IndexOf(notes, a[2]);
            bool ans = Try(n1, n2, n3) || Try(n1, n3, n2) || Try(n2, n1, n3) || Try(n2, n3, n1) || Try(n3, n2, n1) || Try(n3, n1, n2);
            if (!ans)
                writer.Write("strange");

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;

public class Fffuuuu {
    String[] notes = new String[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };
    Int32 Eval(String n) {
        return Array.IndexOf(notes, n);
    }
    Int32 Distance(String x, String y) {
        Int32 res = Eval(y) - Eval(x);
        return res < 0 ? res + notes.Length : res;
    }
    String Find(String[] token) {
        for (Int32 ia = 0; ia < 3; ++ia) {
            for (Int32 ib = 0; ib < 3; ++ib) {
                for (Int32 ic = 0; ic < 3; ++ic) {
                    if (ia != ib && ib != ic && ia != ic) {
                        if (Distance(token[ia], token[ib]) == 4 && Distance(token[ib], token[ic]) == 3) {
                            return "major";
                        } else if (Distance(token[ia], token[ib]) == 3 && Distance(token[ib], token[ic]) == 4) {
                            return "minor";
                        }
                    }
                }
            }
        }
        return "strange";
    }
    public Fffuuuu() {
        Console.WriteLine(Find(Console.ReadLine().Split(' ')));
    }
    public static void Main() {
#if DEBUG
        Console.SetIn(new System.IO.StreamReader("in.txt"));
#endif
        new Fffuuuu();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASM
{
    class Program
    {
        public static string[] notes = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };
        public static string output = "strange";
        static void Main(string[] args)
        {
            string[] traids = Console.ReadLine().Split(' ').ToArray<string>();
            premutations(traids, 0);
            Console.WriteLine(output);
            //Console.ReadLine();
        }
        /*
        */
        static void premutations(string[] traid, int currPlace)
        {
            if (currPlace != 0)
            {
                if(dTones(traid[0], traid[1]) == 4 && dTones(traid[1], traid[2]) == 3)
                {
                    output = "major";
                } else if (dTones(traid[0], traid[1]) == 3 && dTones(traid[1], traid[2]) == 4)
                {
                    output = "minor";
                }
            }

            if ((currPlace+1) == traid.Length) return;

            for(int i=currPlace; i < traid.Length - currPlace; i++)
            {
                string oldC = traid[currPlace];
                string newC = traid[currPlace + i];
                traid[currPlace] = newC;
                traid[currPlace + i] = oldC;
                premutations(traid, currPlace + 1);
                traid[currPlace] = oldC;
                traid[currPlace + i] = newC;
            }
        }

        static int dTones(string firstNote, string secondNote)
        {
            int i = 0, j = 0;
            for(int k = 0; k < 12; k++)
            {
                if(notes[k] == firstNote)
                {
                    i = k+1;
                }
                if (notes[k] == secondNote)
                {
                    j = k+1;
                }
            }
            if (j > i) return (j - i);
            else if (i > j) return (12 - i) + j;
            else return 12;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

class Solver
{
    public void Solve()
    {
        var ss = CF.ReadLine().Split(' ');
        int[] ns = new int[3];
        int i = 0;
        foreach (var s in ss)
        {
            int n = 0;
            switch (s)
            {
                case "C": n = 0; break;
                case "C#": n = 1; break;
                case "D": n = 2; break;
                case "D#": n = 3; break;
                case "E": n = 4; break;
                case "F": n = 5; break;
                case "F#": n = 6; break;
                case "G": n = 7; break;
                case "G#": n = 8; break;
                case "A": n = 9; break;
                case "B": n = 10; break;
                case "H": n = 11; break;
            }
            ns[i++] = n;
        }

        int r1 = (12 + ns[1] - ns[0]) % 12;
        int r2 = (12 + ns[2] - ns[0]) % 12;

        if (
            (r1 == 4 && r2 == 7) ||
            (r1 == 7 && r2 == 4) ||
            (r1 == 3 && r2 == 8) ||
            (r1 == 8 && r2 == 3) ||
            (r1 == 5 && r2 == 9) ||
            (r1 == 9 && r2 == 5)
            )
            CF.WriteLine("major");
        else if (
            (r1 == 3 && r2 == 7) ||
            (r1 == 7 && r2 == 3) ||
            (r1 == 5 && r2 == 8) ||
            (r1 == 8 && r2 == 5) ||
            (r1 == 4 && r2 == 9) ||
            (r1 == 9 && r2 == 4)
            )
            CF.WriteLine("minor");
        else
            CF.WriteLine("strange");
    }

    //  test
    static Utils CF = new Utils(new[]{
@"
C E G
",

@"
C# B F
",
@"
A B H
"

    });
    #region test

    static void Main(string[] args)
    {
#if DEBUG
        for (int t=0;t<CF.TestCount;t++ )
        {
            CF.Test(t);
            new Solver().Solve();
        }
#else
        new Solver().Solve();
#endif
    }

    class Utils
    {
        public void Test(int t)
        {
            _lines = new List<string>();
            string[] ss = _test_input[t].Replace("\n", "").Split('\r');
            for (int i = 0; i < ss.Length; i++)
            {
                if (
                    (i == 0 || i == ss.Length - 1) &&
                    ss[i].Length == 0
                    )
                    continue;

                _lines.Add(ss[i]);
            }
        }

        public int TestCount
        {
            get
            {
                return _test_input.Length;
            }
        }

        public string ReadLine()
        {
#if DEBUG
            string s = null;
            if (_lines.Count > 0)
            {
                s = _lines[0];
                _lines.RemoveAt(0);
            }
            return s;

#else
            //return _sr.ReadLine();
        return Console.In.ReadLine();
#endif
        }

        public void WriteLine(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.WriteLine(o);
#else
            //_sw.WriteLine(o);
        Console.WriteLine(o);
#endif
        }

        public void Write(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.Write(o);
#else
                //_sw.Write(o);
        Console.Write(o);
#endif
        }

        string[] _test_input;

        List<string> _lines;

#if DEBUG
        public Utils(string[] test_input)
        {
            _test_input = test_input;
        }
#else

        public Utils(string[] dummy)
        {
            //_sr = new System.IO.StreamReader("input.txt");
            //_sw = new System.IO.StreamWriter("output.txt");
        }
#endif

    }

    #endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A88
{
    class Program
    {
        static String[] temp = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

        static int Count(string x, string y)
        {
            bool boolya = false;
            int count = 0;
            int i = 0;
            while (true)
            {
                if (temp[i].Equals(x))
                {
                    boolya = true;
                    i++;
                    if (i == 12)
                        i = 0;
                }
                if (!(boolya))
                {
                    i++;
                    if (i == 12)
                        i = 0;
                }
                if (boolya && (!(temp[i].Equals(x))) && (!(temp[i].Equals(y))))
                {
                    count++;
                    i++;
                    if (i == 12)
                        i = 0;
                }
                if (boolya && (temp[i].Equals(y)))
                {
                    break;
                }

            }
            return count++;
        }
        static void Main(string[] args)
        {
            String[] s = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            int flag = 0;
            int r = Count(s[0], s[1]);
            int l = Count(s[1], s[2]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[0], s[2]);
            l = Count(s[2], s[1]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[1], s[0]);
            l = Count(s[0], s[2]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[1], s[2]);
            l = Count(s[2], s[0]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[2], s[0]);
            l = Count(s[0], s[1]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[2], s[1]);
            l = Count(s[1], s[0]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            switch (flag)
            {
                case 0:
                    Console.WriteLine("strange");
                    break;
                case 1:
                    Console.WriteLine("major");
                    break;
                case 2:
                    Console.WriteLine("minor");
                    break;
                default:
                    break;
            }
        }
    }
}