Codeforces Round 538 (Div. 2)
C
Trailing Loves (or L'oeufs?)
Codeforces
1700
原题
← BD →
翻译中…

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 $9200$ 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 $n$ and $b$ (in decimal notation), your task is to calculate the number of trailing zero digits in the $b$-ary (in the base/radix of $b$) representation of $n\,!$ (factorial of $n$).

翻译中…

Input

翻译中…

The only line of the input contains two integers $n$ and $b$ ($1 \le n \le 10^{18}$, $2 \le b \le 10^{12}$).

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

In the first example, $6!_{(10)} = 720_{(10)} = 880_{(9)}$.

翻译中…

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

翻译中…

The representation of the number $x$ in the $b$-ary base is $d_1, d_2, \ldots, d_k$ if $x = d_1 b^{k - 1} + d_2 b^{k - 2} + \ldots + d_k b^0$, where $d_i$ are integers and $0 \le d_i \le b - 1$. For example, the number $720$ from the first example is represented as $880_{(9)}$ since $720 = 8 \cdot 9^2 + 8 \cdot 9 + 0 \cdot 1$.

翻译中…

You can read more about bases here.

翻译中…

样例

Input #1
6 9
Output #1
1
InputCopy OutputCopy
Input #2
38 11
Output #2
3
InputCopy OutputCopy
Input #3
5 2
Output #3
3
InputCopy OutputCopy
Input #4
5 10
Output #4
1
InputCopy OutputCopy
题目信息
题号
1114C
时间限制
2 s
内存限制
256 MB
标签
暴力
模拟
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。