PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000173. Số chữ số 0 tận cùng của giai thừa theo cơ số (Trailing Loves (or L'oeufs?))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số chữ số 0 tận cùng của giai thừa theo cơ số (Trailing Loves (or L'oeufs?))

Trailing Loves (or L'oeufs?)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

The number of trailing zero digits of an integer depends on the numeral base. For instance, 120120 has one trailing zero in decimal notation, while its binary representation 111100021111000_2 has three trailing zero digits.

Given integers nn and bb, find the number of consecutive trailing zero digits in the base-bb representation of n!n!, where n!=1⋅2⋯nn!=1\cdot2\cdots n. A single trailing zero means divisibility by bb; two trailing zeros mean divisibility by b2b^2, and so on.

Print the number of zeros; do not construct the factorial or its base-bb representation.

Input

One line containing two integers nn and bb.

Output

Print one nonnegative integer: the number of trailing zeros of n!n! in base bb.

Subtasks

  • Subtask 1 (20 points): 1≤n≤106,2≤b≤1061 \le n \le 10^6,\quad 2 \le b \le 10^6.
  • Subtask 2 (30 points): 1≤n≤1012,2≤b≤1091 \le n \le 10^{12},\quad 2 \le b \le 10^9.
  • Subtask 3 (50 points): 1≤n≤1018,2≤b≤10121 \le n \le 10^{18},\quad 2 \le b \le 10^{12}.

Examples

Example 1

Input

6 9

Output

1

Explanation

6!=720=8⋅92+8⋅9+0=88096!=720=8\cdot9^2+8\cdot9+0=880_9, which has exactly one trailing zero.

Example 2

Input

5 2

Output

3

Explanation

5!=120=111100025!=120=1111000_2 ends with three zero digits.