题目传送门 题意:很裸,就是求C (n, m) % (p1 * p2 * p3 * .... * pk) 分析:首先n,m<= 1e18, 要用到Lucas定理求大组合数取模,当然p[]的乘积<=1e18不能直接计算,但是pi<=1e5.接下来要知道中国剩余定理,所以先对每个pi计算出bi,注意在中国剩余定理的两数相乘会爆long long,所以用乘法取模,"但是这样的话exgcd返回值如果是负数就会出错,所以乘之前要取模成正的",这句话不是很懂. 收获:老祖宗的智慧…
题目链接: Hdu 5446 Unknown Treasure 题目描述: 就是有n个苹果,要选出来m个,问有多少种选法?还有k个素数,p1,p2,p3,...pk,结果对lcm(p1,p2,p3.....,pk)取余. 解题思路: Lucas + 中国剩余定理,注意的是中国剩余定理的时候有可能会爆long long.然后用一个快速加法就好辣. #include <cstdio> #include <cstring> #include <iostream> #inclu…
HDU 5446 Unknown Treasure 题意:求C(n, m) %(p[1] * p[2] ··· p[k])     0< n,m < 1018 思路:这题基本上算是模版题了,Lucas定理求C(n,m),再用中国剩余定理合并模方程,因为LL相乘会越界,所以用到按位乘. #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #inc…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5446 Unknown Treasure 问题描述 On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere…
题目描述 n个人在w*h的监狱里面想要逃跑,已知他们的同伙在坐标(bi,h)接应他们,他们现在被关在(ai,1)现在他们必须要到同伙那里才有逃出去的机会,这n个人又很蠢只会从(x,y)->(x+1,y),(x,y+1)并且这他们走过的路径不能相交如果相交第一个经过后就会有第二个人经过时候就会有一名狱警在那等他,第二个人就会被抓,假设他们不会同时踩到某个格子,那么他们的逃跑路线有多少不同的方案数.如果两个方案不同那么存在一个人踩的格子至少有一个是另外一个方案的没踩过 输入 第一行一个t(t<=2…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5446 题目大意:求C(n, m) % M, 其中M为不同素数的乘积,即M=p1*p2*...*pk, 1≤k≤10.1≤m≤n≤10^18. 分析: 如果M是素数,则可以直接用lucas定理来做,但是M不是素数,而是素数的连乘积.令C(n, m)为 X ,则可以利用lucas定理分别计算出 X%p1,X%p2, ... , X % pk的值,然后用中国剩余定理来组合得到所求结果. 比较坑的地方是,…
题目链接 求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…
Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2209    Accepted Submission(s): 821 Problem Description On the way to the next secret treasure hiding place, the mathematician…
Unknown Treasure Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5446 Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician ent…
1. 题目描述题目很简单,就是求$C(n,m) % M$. 2. 基本思路这是一道应用了众多初等数论定理的题目,因为数据范围较大因此使用Lucas求$C(n,m) % P$.而M较大,因此通过$a[i] = C(n,m)%P_i$再综合中国剩余定理可解.由于数据可能为$10^{18}$,再进行乘法可能超long long.因此,还需要模拟乘法. 3. 代码 /* 5446 */ #include <iostream> #include <sstream> #include <…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5446 [题目大意] 给出一个合数M的每一个质因子,同时给出n,m,求C(n,m)%M. [题解] 首先我们可以用Lucas定理求出对答案对每个质因子的模,然后我们发现只要求解这个同余方程组就可以得到答案,所以我们用中国剩余定理解决剩下的问题. [代码] #include <cstdio> #include <cstring> #include <algorithm> u…
Each test case starts with three integers n,m,k(1≤m≤n≤1018,1≤k≤10) on a line where k is the number of primes. Following on the next line are kdifferent primes p1,...,pk. It is guaranteed that M=p1⋅p2⋅⋅⋅pk≤1018 and pi≤105 for every i∈{1,...,k}.   Outp…
Problem Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure chest with a com…
Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 721    Accepted Submission(s): 251 Problem Description On the way to the next secret treasure hiding place, the mathematician d…
Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician…
>On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure chest with a combination lock and s…
数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit][Status][Discuss] Description "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久很久以前,在山的那边海的那边的某片风水宝地曾经存在过一个猪王国.猪王国地…
代码: #include"bits/stdc++.h" #define db double #define ll long long #define vec vector<ll> #define Mt vector<vec> #define ci(x) scanf("%d",&x) #define cd(x) scanf("%lf",&x) #define cl(x) scanf("%lld&qu…
题目大意:求$G^{\sum_{m|n} C_{n}^{m}}\;mod\;999911659\;$的值$(n,g<=10^{9})$ 并没有想到欧拉定理.. 999911659是一个质数,所以$\varphi(p)=p-1$ 利用欧拉定理,降幂化简式子$G^{\sum_{m|n} C_{n}^{m}\;mod\;\varphi(p)}$ 这样,指数部分可以用$Lucas$+中国剩余定理求解 然而..$G>10^9$很大,可能和模数$999911659$不互质!所以质数要额外加上$\varph…
Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2389    Accepted Submission(s): 885 Problem Description On the way to the next secret treasure hiding place, the mathematician…
链接: hdu 5446 http://acm.hdu.edu.cn/showproblem.php?pid=5446 题意: 给你三个数$n, m, k$ 第二行是$k$个数,$p_1,p_2,p_3 \cdots p_k$ 所有$p$的值不相同且p都是质数 求$C(n, m) \ \%\  (p_1*p_2*p_3* \cdots *p_k)$的值 范围:$1\leq m\leq n\leq 1e18,\ 1\leq k\leq 10,p_i\leq 1e5$,保证$p_1*p_2*p_3*…
题意:M=p1*p2*...pk:求C(n,m)%M,pi小于10^5,n,m,M都是小于10^18. pi为质数 M不一定是质数 所以只能用Lucas定理求k次 C(n,m)%Pi最后会得到一个同余方程组x≡B[0](mod p[0])x≡B[1](mod p[1])x≡B[2](mod p[2])......解这个同余方程组 用中国剩余定理 Sample Input19 5 23 5 Sample Output6 # include <iostream> # include <cst…
题目链接:https://nanti.jisuanke.com/t/A1842 题目大意:给定整数n,m,k,其中1≤m≤n≤1018,k≤10, 然后给出k个素数,保证M=p[1]*p[2]……*p[k]≤1018,p[i]≤105 求C(n,m)%(p[1]*p[2]……*p[k]) 解题思路:因为模数太大,所以我们先用卢卡斯定理求出对每个素数的模,然后再通过中国剩余定理就可以求得对它们的乘积的模. 代码: #include<bits/stdc++.h> using namespace s…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5446 C(n, m) % (p1*p2*p3*...*pk)的值 其实这个就是中国剩余定理最后算出结果后的最后一步求余 那C(n, m)相当于以前我们需要用中国剩余定理求的值 然而C(n, m)太大,我们只好先算出 C(n, m) % p1 = r1 C(n, m) % p2 = r2 C(n, m) % p3 = r3 . . . C(n, m) % pk = rk 用Lucas,这些r1,r2,…
[bzoj1951]: [Sdoi2010]古代猪文 因为999911659是个素数 欧拉定理得 然后指数上中国剩余定理 然后分别lucas定理就好了 注意G==P的时候的特判 /* http://www.cnblogs.com/karl07/ */ #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using…
题目 "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久很久以前,在山的那边海的那边的某片风水宝地曾经存在过一个猪王国.猪王国地理位置偏僻,实施的是适应当时社会的自给自足的庄园经济,很少与外界联系,商贸活动就更少了.因此也很少有其他动物知道这样一个王国. 猪王国虽然不大,但是土地肥沃,屋舍俨然.如果一定要拿什么与之相比的话,那就只能是东晋陶渊明笔下的大家想象中的桃花源了.猪王勤政爱…
题意:n件礼物,送给m个人,每人的礼物数确定,求方案数. 解题关键:由于模数不是质数,所以由唯一分解定理, $\bmod  = p_1^{{k_1}}p_2^{{k_2}}......p_s^{{k_s}}$ 然后,分别求出每个组合数模每个$p_i^{{k_i}}$的值,这里可以用扩展lucas定理求解,(以下其实就是扩展lucas定理的简略证明) 关于$C_n^m\% {p^k}$, $C_n^m = \frac{{n!}}{{m!(n - m)!}}$, 我们以$n=19,p=3,k=2$为…
数论_CRT(中国剩余定理)& Lucas (卢卡斯定理) 前言 又是一脸懵逼的一天. 正文 按照道理来说,我们应该先做一个介绍. 中国剩余定理 中国剩余定理,Chinese Remainder Theorem,又称孙子定理,给出了一元线性同余方程组的有解判定条件,并用构造法给出了通解的具体形式. 现在有方程组:中国剩余定理指出: 扩展中国剩余定理 在一般情况下,要求任两个数互质这个条件太苛刻了,CRT派不上用场,我们需要一个更具普遍性的结论,这就是EX-CRT.虽然是称为EX-CRT,但这个定…
Mysterious For-HDU 4373 题目描述 MatRush is an ACMer from ZJUT, and he always love to create some special programs. Here we will talk about one of his recent inventions. This special program was called "Mysterious For", it was written in C++ languag…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5446 题意: On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, sh…