摘要: 组合计数 错排问题 具体见这~ exLucas 具体见这~ \[\mathbb{END} \] 阅读全文
posted @ 2025-05-05 21:07 tyh_27 阅读(2) 评论(0) 推荐(0)
摘要: 数论 逆元 具体见这~ 扩展中国剩余定理(EXCRT) 具体见这~ 卢卡斯定理(Lucas) 具体见这~ BSGS 具体见这~ exBSGS 具体见这~ \[\large{\mathbb{END}} \] 阅读全文
posted @ 2025-04-15 21:28 tyh_27 阅读(1) 评论(0) 推荐(0)
摘要: 扩展中国剩余定理(EXCRT) ​ 题目:​P4777-洛谷​ 为什么不写中国剩余定理,因为 A_zjzj 大佬表示这并没有用处... 简述 如果给定 \(n\) 个同余方程组 \[\begin{cases} x \equiv b_1 \pmod {a_1} \\ x \equiv b_2 \pmo 阅读全文
posted @ 2025-05-10 15:55 tyh_27 阅读(13) 评论(0) 推荐(0)
摘要: 错排问题 题意 已知一个长度为 \(n\) 的排列 \(p_1,p_2,\dots,p_n\)。求 \(\forall i \in [1,n]\text{ s.t. }p_i \ne i\) 的方案数。 法1 考虑容斥原理。 因为容斥求的是并集(\(\cup\))但这里求的是交集(\(\cap\)) 阅读全文
posted @ 2025-05-07 21:38 tyh_27 阅读(1) 评论(0) 推荐(0)
摘要: exLucas 前置知识:EXCRT(或 CRT) 题面 给定整数 \(n,m,p\) 的值,求出 \(\binom{n}{m} \bmod p\) 的值,但不保证 \(p\) 为质数,\(n,m \leq 10^{18}\)。 做法 此时用 Lucas 定理显然是不行的(说实话 exLucas 的 阅读全文
posted @ 2025-05-05 20:19 tyh_27 阅读(3) 评论(0) 推荐(0)
摘要: exBSGS \[a^x \equiv b \pmod p \]跟 BSGS 差不多,只是多了 \(p\) 可以不为质数这一条件。 做法 首先你需要知道一个同余方程的性质: 给定一个同余式 \(a \equiv b\pmod p\)。 若存在 \(d\) 满足 \(d\mid a,d\mid b,d 阅读全文
posted @ 2025-04-23 21:19 tyh_27 阅读(3) 评论(0) 推荐(0)
摘要: BSGS 题目:P3846-洛谷 题面 给定一个质数 \(p\),以及一个整数 \(g\),一个整数 \(a\),要求计算一个最小的非负整数 \(x\),满足 \[g^x \equiv a \pmod p \]做法 对于这种题目,可以用大步小步算法(Baby Step,Giant Step,简称 B 阅读全文
posted @ 2025-04-22 20:20 tyh_27 阅读(2) 评论(0) 推荐(0)
摘要: 卢卡斯定理(Lucas) 题目:P3807-洛谷 题面 给定整数 \(n,m,p\) 的值,求出 \(\binom{n+m}{n} \bmod p\) 的值,且保证 \(p\) 为质数。 做法 Step 0: 卢卡斯定理: \[\binom{n}{m}\equiv \binom{\lfloor{\f 阅读全文
posted @ 2025-04-16 17:01 tyh_27 阅读(1) 评论(0) 推荐(0)
摘要: 逆元 定义 若 \(ax\equiv1\pmod p\),且 \(a\) 与 \(p\) 互质,则称 \(x\) 为 \(a\) 的逆元,记为 \(a^{-1}\)。 所以对于求解 \(\frac{a}{b} \bmod p\),我们可以先求出 \(b\) 的逆元 \(b^{-1}\),在将 \(a 阅读全文
posted @ 2025-04-16 16:56 tyh_27 阅读(1) 评论(0) 推荐(0)