CF2153E.Zero Trailing Factorial
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For all positive integers x≥1 and k≥2, let vk(x!) denote the number of trailing zeros in the base-k representation of x!=x⋅(x−1)⋅…⋅1. Formally, vk(x!) is defined as the largest integer i such that ki divides x!.
For a prime number p, we can calculate vp(x!)=j=1∑∞⌊pjx⌋∗. If k is not prime, write its prime factorization as k=∏piei, where pi are distinct prime factors and ei 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≥2, the weight of the pair (a,b) with respect to k, denoted by wk(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) as the minimum weight of the pair (a,b) with respect to k, taken over all integers k with 2≤k≤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 fm(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 10100.
∗⌊y⌋ denotes the floor of y, which is the greatest integer less than or equal to y.
对于所有正整数 x≥1 和 k≥2,记 vk(x!) 为 x!=x⋅(x−1)⋅…⋅1 在 k 进制表示下的末尾零的个数。形式上,vk(x!) 定义为满足 ki∣x! 的最大整数 i。
对于素数 p,可计算 vp(x!)=j=1∑∞⌊pjx⌋∗。若 k 不是素数,将其素因数分解写为 k=∏piei,其中 pi 是互异的素因子,ei 是其对应的指数。则有
v_k(x!)=minlimits_ileftlfloorfracv_p_i(x!)e_irightrfloor.
对任意两个正整数 a 和 b,以及任意整数 k≥2,定义数对 (a,b) 关于 k 的权值 wk(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) 为在所有满足 2≤k≤m 的整数 k 中,数对 (a,b) 关于 k 的权值的最小值:
f_m(a,b)=minlimits_2leklemw_k(a,b).
给定两个整数 n 和 m,你的任务是计算所有小于 n 的正整数 x 对应的 fm(x,n) 之和:
sum_1lexlen−1f_m(x,n).
可以证明,在本题给定的约束条件下,该结果严格小于 10100。
∗⌊y⌋ 表示 y 的向下取整,即不超过 y 的最大整数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.
The first and only line of each test case contains two integers n and m (2≤n≤m≤107) — the parameters of the function.
Note that there are no constraints on the sum of n,m over all test cases.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 m(2≤n≤m≤107)——该函数的参数。
注意:所有测试用例的 n 与 m 的总和没有额外限制。
输出格式
For each test case, output a single integer representing 1≤x≤n−1∑fm(x,n).
对于每个测试用例,输出一个整数,表示 1≤x≤n−1∑fm(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≤5:
- v3(1!)=v3(2!)=0, since 3 does not divide both 1 and 2.
- v3(3!)=v3(6)=1, since 3 divides 6, but 32=9 does not.
Therefore, w3(1,3)=w3(2,3)=min(0,1)=0. It can be shown that this is the minimum weight across all 2≤k≤5, so f5(1,3)=f5(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)=0. For f7(5,6), we consider k=6≤7:
- v6(5!)=v6(120)=1, since 6 divides 120, but 62=36 does not.
- v6(6!)=v6(720)=2, since 62=36 divides 720, but 63=216 does not.
Therefore, w6(5,6)=min(1,2)=1. It can be shown that this is the minimum weight across all 2≤k≤7, so f7(5,6)=1.
Note: choosing k=7≤7 does not work, because v7(5!)=v7(6!)=0, so w7(5,6)=10100.
In the third test case, it can be shown that f10(1,6)=f10(2,6)=f10(3,6)=f10(4,6)=0. For f10(5,6), we consider k=9≤10:
- v9(5!)=v9(120)=0, since 9 does not divide 120.
- v9(6!)=v9(720)=1, since 9 divides 720, but 92=81 does not.
Therefore, w9(5,6)=min(0,1)=0. It can be shown that this is the minimum weight across all 2≤k≤10, so f10(5,6)=0.
在第一个测试用例中,考虑 k=3≤5:
- v3(1!)=v3(2!)=0,因为 3 不能整除 1 和 2。
- v3(3!)=v3(6)=1,因为 3 能整除 6,但 32=9 不能整除 6。
因此,w3(1,3)=w3(2,3)=min(0,1)=0。可以证明,这是所有满足 2≤k≤5 的 k 中的最小权值,故 f5(1,3)=f5(2,3)=0。
在第二个测试用例中,可以证明 f7(1,6)=f7(2,6)=f7(3,6)=f7(4,6)=0。对于 f7(5,6),我们考虑 k=6≤7:
- v6(5!)=v6(120)=1,因为 6 能整除 120,但 62=36 不能整除 120。
- v6(6!)=v6(720)=2,因为 62=36 能整除 720,但 63=216 不能整除 720。
因此,w6(5,6)=min(1,2)=1。可以证明,这是所有满足 2≤k≤7 的 k 中的最小权值,故 f7(5,6)=1。
注意:选择 k=7≤7 不可行,因为 v7(5!)=v7(6!)=0,所以 w7(5,6)=10100。
在第三个测试用例中,可以证明 f10(1,6)=f10(2,6)=f10(3,6)=f10(4,6)=0。对于 f10(5,6),我们考虑 k=9≤10:
- v9(5!)=v9(120)=0,因为 9 不能整除 120。
- v9(6!)=v9(720)=1,因为 9 能整除 720,但 92=81 不能整除 720。
因此,w9(5,6)=min(0,1)=0。可以证明,这是所有满足 2≤k≤10 的 k 中的最小权值,故 f10(5,6)=0。
输入解题思路,AI测评打分。不知道怎么写?