CF2153E.Zero Trailing Factorial

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

For a prime number pp, we can calculate vp(x!)=∑j=1∞⌊xpj⌋v_p(x!) = \sum\limits_{j=1}^\infty \left\lfloor \frac{x}{p^j}\right\rfloor∗^{\text{∗}}. If kk is not prime, write its prime factorization as k=∏pieik = \prod p_i^{e_i}, where pip_i are distinct prime factors and eie_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 aa and bb, and any integer k≥2k\ge 2, the weight of the pair (a,b)(a, b) with respect to kk, denoted by wk(a,b)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 fm(a,b)f_m(a, b) as the minimum weight of the pair (a,b)(a, b) with respect to kk, taken over all integers kk with 2≤k≤m2\le k\le m: $$f_m(a, b)=\min\limits_{2\le k\le m}w_k(a, b).$$

You are given two integers nn and mm. Your task is to compute the sum of fm(x,n)f_m(x, n) over all positive integers xx less than nn: $$\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 1010010^{100}.

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

对于所有正整数 x≥1x\ge 1 和 k≥2k\ge 2,记 vk(x!)v_k(x!) 为 x!=x⋅(x−1)⋅…⋅1x! = x\cdot (x-1)\cdot \ldots \cdot 1 在 kk 进制表示下的末尾零的个数。形式上,vk(x!)v_k(x!) 定义为满足 ki∣x!k^i \mid x! 的最大整数 ii。

对于素数 pp,可计算 vp(x!)=∑j=1∞⌊xpj⌋v_p(x!) = \sum\limits_{j=1}^\infty \left\lfloor \frac{x}{p^j}\right\rfloor∗^{\text{∗}}。若 kk 不是素数,将其素因数分解写为 k=∏pieik = \prod p_i^{e_i},其中 pip_i 是互异的素因子,eie_i 是其对应的指数。则有

v_k(x!)=minlimits_ileftlfloorfracv_p_i(x!)e_irightrfloor.v\_k(x!) = \\min\\limits\_i \\left\\lfloor \\frac{v\_{p\_i}(x!)}{e\_i}\\right\\rfloor.

对任意两个正整数 aa 和 bb,以及任意整数 k≥2k\ge 2,定义数对 (a,b)(a, b) 关于 kk 的权值 wk(a,b)w_k(a, b) 为

w\_k(a, b) = \\begin{cases}\\min(v\_k(a!), v\_k(b!)) & \\text{若 }v\_k(a!)\\neq v\_k(b!)\\text{;}\\\\10^{100} & \\text{否则。}\\end{cases}

接着,定义 fm(a,b)f_m(a, b) 为在所有满足 2≤k≤m2\le k\le m 的整数 kk 中,数对 (a,b)(a, b) 关于 kk 的权值的最小值:

f_m(a,b)=minlimits_2leklemw_k(a,b).f\_m(a, b)=\\min\\limits\_{2\\le k\\le m}w\_k(a, b).

给定两个整数 nn 和 mm,你的任务是计算所有小于 nn 的正整数 xx 对应的 fm(x,n)f_m(x, n) 之和:

sum_1lexlen−1f_m(x,n).\\sum\_{1\\le x\\le n - 1} f\_m(x, n).

可以证明,在本题给定的约束条件下,该结果严格小于 1010010^{100}。

∗^{\text{∗}}⌊y⌋\lfloor y\rfloor 表示 yy 的向下取整,即不超过 yy 的最大整数。

输入格式

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

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

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 mm(2≤n≤m≤1072\le n\le m\le 10^7)——该函数的参数。

注意:所有测试用例的 nn 与 mm 的总和没有额外限制。

输出格式

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

对于每个测试用例,输出一个整数,表示 ∑1≤x≤n−1fm(x,n)\sum\limits_{1\le x\le n - 1} f_m(x, n)。

输入输出样例

  • 输入#1

    5
    3 5
    6 7
    6 10
    36 68
    10000000 10000000

    输出#1

    0
    1
    0
    13
    279933

说明/提示

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

  • v3(1!)=v3(2!)=0v_3(1!) = v_3(2!) = 0, since 33 does not divide both 11 and 22.
  • v3(3!)=v3(6)=1v_3(3!) = v_3(6) = 1, since 33 divides 66, but 32=93^2 = 9 does not.

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

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

  • v6(5!)=v6(120)=1v_6(5!) = v_6(120) = 1, since 66 divides 120120, but 62=366^2 = 36 does not.
  • v6(6!)=v6(720)=2v_6(6!) = v_6(720) = 2, since 62=366^2 = 36 divides 720720, but 63=2166^3 = 216 does not.

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

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

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

  • v9(5!)=v9(120)=0v_9(5!) = v_9(120) = 0, since 99 does not divide 120120.
  • v9(6!)=v9(720)=1v_9(6!) = v_9(720) = 1, since 99 divides 720720, but 92=819^2 = 81 does not.

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

在第一个测试用例中,考虑 k=3≤5k = 3\le 5:

  • v3(1!)=v3(2!)=0v_3(1!) = v_3(2!) = 0,因为 33 不能整除 11 和 22。
  • v3(3!)=v3(6)=1v_3(3!) = v_3(6) = 1,因为 33 能整除 66,但 32=93^2 = 9 不能整除 66。

因此,w3(1,3)=w3(2,3)=min⁡(0,1)=0w_3(1, 3) = w_3(2, 3) = \min(0, 1) = 0。可以证明,这是所有满足 2≤k≤52\le k\le 5 的 kk 中的最小权值,故 f5(1,3)=f5(2,3)=0f_5(1, 3) = f_5(2, 3) = 0。

在第二个测试用例中,可以证明 f7(1,6)=f7(2,6)=f7(3,6)=f7(4,6)=0f_7(1, 6) = f_7(2, 6) = f_7(3, 6) = f_7(4, 6) = 0。对于 f7(5,6)f_7(5, 6),我们考虑 k=6≤7k = 6\le 7:

  • v6(5!)=v6(120)=1v_6(5!) = v_6(120) = 1,因为 66 能整除 120120,但 62=366^2 = 36 不能整除 120120。
  • v6(6!)=v6(720)=2v_6(6!) = v_6(720) = 2,因为 62=366^2 = 36 能整除 720720,但 63=2166^3 = 216 不能整除 720720。

因此,w6(5,6)=min⁡(1,2)=1w_6(5, 6) = \min(1, 2) = 1。可以证明,这是所有满足 2≤k≤72\le k\le 7 的 kk 中的最小权值,故 f7(5,6)=1f_7(5, 6) = 1。

注意:选择 k=7≤7k = 7 \le 7 不可行,因为 v7(5!)=v7(6!)=0v_7(5!) = v_7(6!) = 0,所以 w7(5,6)=10100w_7(5, 6) = 10^{100}。

在第三个测试用例中,可以证明 f10(1,6)=f10(2,6)=f10(3,6)=f10(4,6)=0f_{10}(1, 6) = f_{10}(2, 6) = f_{10}(3, 6) = f_{10}(4, 6) = 0。对于 f10(5,6)f_{10}(5, 6),我们考虑 k=9≤10k = 9\le 10:

  • v9(5!)=v9(120)=0v_9(5!) = v_9(120) = 0,因为 99 不能整除 120120。
  • v9(6!)=v9(720)=1v_9(6!) = v_9(720) = 1,因为 99 能整除 720720,但 92=819^2 = 81 不能整除 720720。

因此,w9(5,6)=min⁡(0,1)=0w_9(5, 6) = \min(0, 1) = 0。可以证明,这是所有满足 2≤k≤102\le k\le 10 的 kk 中的最小权值,故 f10(5,6)=0f_{10}(5, 6) = 0。

输入解题思路,AI测评打分。不知道怎么写?

首页