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

#SP0000216. Trọng số giai thừa theo nhiều cơ số (Zero Trailing Factorial)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Trọng số giai thừa theo nhiều cơ số (Zero Trailing Factorial)

Zero Trailing Factorial

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

For integers x≥1x\ge1 and k≥2k\ge2, let vk(x!)v_k(x!) be the largest integer t≥0t\ge0 such that ktk^t divides x!x!. This equals the number of trailing zeros of x!x! in base kk.

For prime pp,

$$v_p(x!)=\sum_{j\ge1}\left\lfloor\frac{x}{p^j}\right\rfloor.$$

For k=∏ipieik=\prod_i p_i^{e_i} with distinct primes pip_i,

$$v_k(x!)=\min_i\left\lfloor\frac{v_{p_i}(x!)}{e_i}\right\rfloor.$$

For positive integers a,ba,b and k≥2k\ge2, define

$$w_k(a,b)=\begin{cases}\min(v_k(a!),v_k(b!)),&v_k(a!)\ne v_k(b!),\\10^{100},&v_k(a!)=v_k(b!).\end{cases}$$

For a limit mm, define

fm(a,b)=min⁡2≤k≤mwk(a,b).f_m(a,b)=\min_{2\le k\le m}w_k(a,b).

Given integers n,mn,m, compute exactly

∑x=1n−1fm(x,n).\sum_{x=1}^{n-1}f_m(x,n).

The answer is guaranteed to be strictly less than 1010010^{100}.

Input

The only line contains the integers n,mn,m.

Output

Print one integer: the exact value of the defined sum.

Subtasks

  • Subtask 1 (20 points): 2≤n≤m≤1002\le n\le m\le 100.
  • Subtask 2 (30 points): 2≤n≤m≤1042\le n\le m\le 10^4.
  • Subtask 3 (50 points): 2≤n≤m≤1072\le n\le m\le 10^7.

Examples

Input

6 7

Output

1

Explanation

For x=1,2,3,4x=1,2,3,4, an admissible base in [2,7][2,7] gives f7(x,6)=0f_7(x,6)=0. For x=5x=5, choose k=6k=6: v6(5!)=1v_6(5!)=1 because 6∣1206\mid120 but 36∤12036\nmid120, while v6(6!)=2v_6(6!)=2 because 36∣72036\mid720 but 216∤720216\nmid720. They differ, so w6(5,6)=1w_6(5,6)=1, which is minimal for x=5x=5. The sum is 0+0+0+0+1=10+0+0+0+1=1.