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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 and , let be the largest integer such that divides . This equals the number of trailing zeros of in base .
For prime ,
$$v_p(x!)=\sum_{j\ge1}\left\lfloor\frac{x}{p^j}\right\rfloor.$$For with distinct primes ,
$$v_k(x!)=\min_i\left\lfloor\frac{v_{p_i}(x!)}{e_i}\right\rfloor.$$For positive integers and , 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 , define
Given integers , compute exactly
The answer is guaranteed to be strictly less than .
Input
The only line contains the integers .
Output
Print one integer: the exact value of the defined sum.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
6 7
Output
1
Explanation
For , an admissible base in gives . For , choose : because but , while because but . They differ, so , which is minimal for . The sum is .