Codeforces Round 1057 (Div. 2)
E
Zero Trailing Factorial
Codeforces
2400
原题
← DF →
翻译中…

For all positive integers $x\ge 1$ and $k\ge 2$, let $v_k(x!)$ denote the number of trailing zeros in the base-$k$ representation of $x! = x\cdot (x-1)\cdot \ldots \cdot 1$. Formally, $v_k(x!)$ is defined as the largest integer $i$ such that $k^i$ divides $x!$.

翻译中…

For a prime number $p$, we can calculate $v_p(x!) = \sum\limits_{j=1}^\infty \left\lfloor \frac{x}{p^j}\right\rfloor$$^{\text{∗}}$. If $k$ is not prime, write its prime factorization as $k = \prod p_i^{e_i}$, where $p_i$ are distinct prime factors and $e_i$ are their corresponding exponents. Then, $$v_k(x!) = \min\limits_i \left\lfloor \frac{v_{p_i}(x!)}{e_i}\right\rfloor.$$

翻译中…

For any two positive integers $a$ and $b$, and any integer $k\ge 2$, the weight of the pair $(a, b)$ with respect to $k$, denoted by $w_k(a, b)$, is defined as $$w_k(a, b) = \begin{cases}\min(v_k(a!), v_k(b!)) & \text{if }v_k(a!)\neq v_k(b!)\text{;}\\10^{100} & \text{otherwise.}\end{cases}$$

翻译中…

Next, define $f_m(a, b)$ as the minimum weight of the pair $(a, b)$ with respect to $k$, taken over all integers $k$ with $2\le k\le m$: $$f_m(a, b)=\min\limits_{2\le k\le m}w_k(a, b).$$

翻译中…

You are given two integers $n$ and $m$. Your task is to compute the sum of $f_m(x, n)$ over all positive integers $x$ less than $n$: $$\sum_{1\le x\le n - 1} f_m(x, n).$$

翻译中…

It can be shown that under the given constraints, the result is strictly less than $10^{100}$.

翻译中…

$^{\text{∗}}$$\lfloor y\rfloor$ denotes the floor of $y$, which is the greatest integer less than or equal to $y$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

The first and only line of each test case contains two integers $n$ and $m$ ($2\le n\le m\le 10^7$) — the parameters of the function.

翻译中…

Note that there are no constraints on the sum of $n, m$ over all test cases.

翻译中…

Output

翻译中…

For each test case, output a single integer representing $\sum\limits_{1\le x\le n - 1} f_m(x, n)$.

翻译中…

Note

翻译中…

In the first test case, consider $k = 3\le 5$:

翻译中…
  • $v_3(1!) = v_3(2!) = 0$, since $3$ does not divide both $1$ and $2$.
  • $v_3(3!) = v_3(6) = 1$, since $3$ divides $6$, but $3^2 = 9$ does not.
翻译中…

Therefore, $w_3(1, 3) = w_3(2, 3) = \min(0, 1) = 0$. It can be shown that this is the minimum weight across all $2\le k\le 5$, so $f_5(1, 3) = f_5(2, 3) = 0$.

翻译中…

In the second test case, it can be shown that $f_7(1, 6) = f_7(2, 6) = f_7(3, 6) = f_7(4, 6) = 0$. For $f_7(5, 6)$, we consider $k = 6\le 7$:

翻译中…
  • $v_6(5!) = v_6(120) = 1$, since $6$ divides $120$, but $6^2 = 36$ does not.
  • $v_6(6!) = v_6(720) = 2$, since $6^2 = 36$ divides $720$, but $6^3 = 216$ does not.
翻译中…

Therefore, $w_6(5, 6) = \min(1, 2) = 1$. It can be shown that this is the minimum weight across all $2\le k\le 7$, so $f_7(5, 6) = 1$.

翻译中…

Note: choosing $k = 7 \le 7$ does not work, because $v_7(5!) = v_7(6!) = 0$, so $w_7(5, 6) = 10^{100}$.

翻译中…

In the third test case, it can be shown that $f_{10}(1, 6) = f_{10}(2, 6) = f_{10}(3, 6) = f_{10}(4, 6) = 0$. For $f_{10}(5, 6)$, we consider $k = 9\le 10$:

翻译中…
  • $v_9(5!) = v_9(120) = 0$, since $9$ does not divide $120$.
  • $v_9(6!) = v_9(720) = 1$, since $9$ divides $720$, but $9^2 = 81$ does not.
翻译中…

Therefore, $w_9(5, 6) = \min(0, 1) = 0$. It can be shown that this is the minimum weight across all $2\le k\le 10$, so $f_{10}(5, 6) = 0$.

翻译中…

样例

Input #1
5
3 5
6 7
6 10
36 68
10000000 10000000
Output #1
0
1
0
13
279933
InputCopy OutputCopy
题目信息
题号
2153E
时间限制
3 s
内存限制
512 MB
标签
暴力
数学
数论

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