题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4767 题意:求集合{1, 2, 3, ..., n}有多少种划分情况bell[n],最后结果bell[n] mod 95041567. 分析:首先了解三个概念:贝尔数   第二类斯特灵数   中国剩余定理 贝尔数是指基数为n的集合的划分方法的数目. 贝尔数适合递推公式: 每个贝尔数都是"第二类Stirling数"的和 贝尔数满足两个公式:(p为质数)             1) B[n+…
Bell Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4767   Description What? MMM is learning Combinatorics!? Looks like she is playing with the bell sequence now: bell[n] = number of ways to pa…
思路:矩阵快速幂+中国剩余定理!! 查资料得到2个公式:             1) B[n+p] = B[n] + B[n+1] mod p ;             2) B[p^m+n] = m*B[n] + B[n+1] mod p . 用这两个都可以解决这个问题,第二个可以在0ms解决. 质因数分解95041567=31*37*41*43*47,用矩阵快速幂分别求出B[n]%p (p是95041567的质因子)的结果. 这样就得到5个同余等式,在用中国剩余定理求解既可. 代码如下:…
Lucky7 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its body an…
http://acm.hdu.edu.cn/showproblem.php?pid=1573 X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4439    Accepted Submission(s): 1435 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0],…
昨天比赛被虐的这个题目. 今天听斌牛讲过他的思路后就A掉了. 题目的意思是要你求出bell数的第n项对95041567取模. 首先,95041567=31*37*41*43*47: 然后取模就是先分别取模,然后就用中国剩余定理合并了. 现在的问题就是如何求出来B[n]对95041567分别取模的结果了哦. 不错,现在你缺少的就是一个公式——B[P^m+n]==(B[n]+B[n+1])%P——P为任一个质数(来自维基百科). 这样的话我们就可以递推了哦. 从大的开始往小的递推,每次减去一个最大的…
分析: 因为满足任意一组pi和ai,即可使一个“幸运数”被“污染”,我们可以想到通过容斥来处理这个问题.当我们选定了一系列pi和ai后,题意转化为求[x,y]中被7整除余0,且被这一系列pi除余ai的数的个数,可以看成若干个同余方程联立成的一次同余方程组.然后我们就可以很自然而然的想到了中国剩余定理.需要注意的是,在处理中国剩余定理的过程中,可能会发生超出LongLong的情况,需要写个类似于快速幂的快速乘法来处理. 吐槽:赛场上不会快速乘,导致疯狂WA,唉,还是太年轻 代码: #include…
题目链接 求C(n, m)%p的值, n, m<=1e18, p = p1*p2*...pk. pi是质数. 先求出C(n, m)%pi的值, 然后这就是一个同余的式子. 用中国剩余定理求解. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; #define l…
题意: 给定方程 res % 14 = 5 res % 57 = 56 求res 中国剩余定理裸题 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<set> #include<queue> #include<vector> using namespace s…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4767 题意:给出n.求n有多少种划分集合的方式,即bell(n) 思路: #include <iostream>#include <cstdio>#include <string.h>#include <algorithm>#include <cmath>#include <vector>#include <queue>#in…