C. Trailing Loves (or L'oeufs?)

http://codeforces.com/contest/1114/problem/C

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.

Aki is fond of numbers, especially those with trailing zeros. For example, the number 92009200 has two trailing zeros. Aki thinks the more trailing zero digits a number has, the prettier it is.

However, Aki believes, that the number of trailing zeros of a number is not static, but depends on the base (radix) it is represented in. Thus, he considers a few scenarios with some numbers and bases. And now, since the numbers he used become quite bizarre, he asks you to help him to calculate the beauty of these numbers.

Given two integers nn and bb (in decimal notation), your task is to calculate the number of trailing zero digits in the bb -ary (in the base/radix of bb ) representation of n!n! (factorial of nn ).

Input

The only line of the input contains two integers nn and bb (1≤n≤10181≤n≤1018 , 2≤b≤10122≤b≤1012 ).

Output

Print an only integer — the number of trailing zero digits in the bb -ary representation of n!n!

Examples

Input

Copy

6 9

Output

Copy

1

Input

Copy

38 11

Output

Copy

3

Input

Copy

5 2

Output

Copy

3

Input

Copy

5 10

Output

Copy

1

Note

In the first example, 6!(10)=720(10)=880(9)6!(10)=720(10)=880(9) .

In the third and fourth example, 5!(10)=120(10)=1111000(2)5!(10)=120(10)=1111000(2) .

The representation of the number xx in the bb -ary base is d1,d2,…,dkd1,d2,…,dk if x=d1bk−1+d2bk−2+…+dkb0x=d1bk−1+d2bk−2+…+dkb0 , where didi are integers and 0≤di≤b−10≤di≤b−1 . For example, the number 720720 from the first example is represented as 880(9)880(9) since 720=8⋅92+8⋅9+0⋅1720=8⋅92+8⋅9+0⋅1 .

You can read more about bases here.

、好像跟计科院赛的那道题差不多

#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
int prime[maxn];
vector<int>v;
inline void init()
{
    memset(prime,0,sizeof(prime));
    prime[0]=1;
    prime[1]=1;
    for(int i=2; i<maxn; i++)
    {
        if(!prime[i])
        {
            for(int j=2;; j++)
            {
                if(i*j<maxn)
                    prime[i*j]=1;
                else
                    break;
            }
        }
    }
    for(int i=0; i<maxn; i++)
        if(!prime[i])
            v.push_back(i);
}
map<long long,int>mp;
long long n,b;
void solve()
{
    long long temp=b;
    for(int i=0;i<v.size();i++)
    {
        int r=0;
        while(temp%v[i]==0)
        {
            r++;
            temp/=v[i];
        }
        if(r)
            mp[(long long)v[i]]=r;
    }
    if(temp>1)
        mp[temp]=1;
}
long long getans()
{
    long long ans=1e18+6;
    map<long long,int>::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        long long temp=n;
        long long sum=0;
        while(temp)
        {
            sum+=temp/(*it).first;
            temp/=(*it).first;
        }
        ans=min(ans,sum/(*it).second);
    }
    return ans;
}
void run()
{
     cin>>n>>b;
    init();
    solve();
    cout<<getans();
}
int main()
{
   run();
}