#include <fstream>

using namespace std;
ifstream fi("timk.inp");
ofstream fo("timk.out");

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    fi >> n >> m;
    int j = 2,tg = m;
    while (tg != 1)
    {
        while (tg%j == 0)
        {
            tg /= j;
        }
        if (tg == 1) break;
        if (j == 2) ++j;
        else j += 2;
    }
    tg = 0;
    while (n/j != 0)
    {
        tg += n/j;
        j *= j;
    }
    fo << tg;
    return 0;
}

