(ex)Lucas总结】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; int jc[100003]; int p; int ipow(int x, int b) { ll t = 1, w = x;…
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Devu wants to decorate his garden with flowers. He has purchased n boxes…
最近碰到一题,问你求mod (p1*p2*p3*……*pl) ,其中n和m数据范围是1~1e18 , l ≤10 , pi ≤ 1e5为不同的质数,并保证M=p1*p2*p3*……*pl ≤ 1e18 . 要解决这个问题首先需要Lucas定理 或者 C!解法. Lucas定理: 我们令n=sp+q , m=tp+r . q , r ≤ p 那么,然后你只要继续对调用Lucas定理即可. 代码可以递归的去完成这个过程,其中递归终点为t = 0 : 伪代码,时间O(logp(n)*p): int L…
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…
4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 95  Solved: 33[Submit][Status][Discuss] Description 曾经发明了脑洞治疗仪&超能粒子炮的发明家SHTSC又公开了他的新发明:超能粒子炮·改--一种可以发射威力更加 强大的粒子流的神秘装置.超能粒子炮·改相比超能粒子炮,在威力上有了本质的提升.它有三个参数n,k.它会 向编号为0到k的位置发射威力为C(n,…
组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1)  , 此时较简单,在O(n2)可承受的情况下组合数的计算可以直接用杨辉三角递推,边做加法边取模. (2) ,   ,并且是素数 本文针对该取值范围较大又不太大的情况(2)进行讨论. 这个问题可以使用Lucas定理,定理描述: 其中 这样将组合数的求解分解为小问题的乘积,下面考虑计算C(ni, mi) %p. 已知C(n, m) mod p = n!/(m!(…
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…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4315    Accepted Submission(s): 1687 Problem Description Although winter is far away, squirrels have to work day and night to save be…
Description “在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心……” ——选自猪王国民歌 很久很久以前,在山的那边海的那边的某片风水宝地曾经存在过一个猪王国.猪王国地理位置偏僻,实施的是适应当时社会的自给自足的庄园经济,很少与外界联系,商贸活动就更少了.因此也很少有其他动物知道这样一个王国. 猪王国虽然不大,但是土地肥沃,屋舍俨然.如果一定要拿什么与之相比的话,那就只能是东晋陶渊明笔下的大家想象中的桃花源了.猪…
Description 去年的Lucas非常喜欢数论题,但是一年以后的Lucas却不那么喜欢了. 在整理以前的试题时,发现了这样一道题目“求Sigma(f(i)),其中1<=i<=N”,其中 表示i的约数个数.他现在长大了,题目也变难了. 求如下表达式的值:   其中 表示ij的约数个数. 他发现答案有点大,只需要输出模1000000007的值. Input 第一行一个整数n. Output 一行一个整数ans,表示答案模1000000007的值. Sample Input 2 Sample…
Lucas' theorem In number theory, Lucas's theorem expresses the remainder of division of the binomial coefficient by a prime number p in terms of the base p expansions of the integers m and n.     ----wiki 表达式 对于非负整数m.n和素数p,如果有: 则有下式成立: 牛刀小试 题目链接:hdu-…
Tom and matrix Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analyse: 直接可以用Lucas定理+快速幂水过的,但是我却作死的用了另一种方法. 方法一:Lucas定理+快速幂水过 方法二:首先问题可以转化为求(0,0),(n,m)这个子矩阵的所有数之和.画个图容易得到一个做法,对于n<=m,答案就是2^0+2^1+...+2^m=2^(m+1)-1,对于n>m…
数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit][Status][Discuss] Description "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久很久以前,在山的那边海的那边的某片风水宝地曾经存在过一个猪王国.猪王国地…
The figure below shows Pascal's Triangle: Baby H divides Pascal's Triangle into some Diagonals, like the following figure: Baby H wants to know the sum of K number in front on the Mth diagonal. Try to calculate it. Input There are multiple test cases…
对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况.就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 这里用到Lusac定理 For non-negative integers m and n and a prime p, the following congruence relation holds: where and are the base p expansions of m and n respectively.…
Lucas的数论 reference 题目在这里> < Pre 数论分块 默认向下取整时. 形如\(\sum\limits_{i=1}^n f\left( \frac{n}{i}\right)\)的求和,由于\(\frac{n}{r}\)的值只有\(\sqrt{n}\)个,可以直接数论分块上. 题解 记原式为\(S(n)\),有 \[S(n)=\sum_{i\rightarrow n}\sum_{j\rightarrow n}[\gcd{i,j}=1]\frac{n}{i}\frac{n}{j…
Lucas的数论(math) 题目描述 去年的今日,Lucas仍然是一个热爱数学的孩子.(现在已经变成业界毒瘤了> <) 在整理以前的试题时,他发现了这么一道题目:求\(\sum\limits_{i=1}^nd(i)\) 随着毒瘤本性的爆发,Lucas灵机一动,编出了一道题: \[\sum\limits_{i=1}^n\sum\limits_{j=1}^nd(ij)\]. 其中\(d(x)\)是一个函数表示\(x\)的约数个数.Lucas脑补了一下,发现这个问题并不单纯- -,于是你只需要输出…
Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB  Description Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best way to show he is alone without a girl friend. The day…
题目大概问小于等于m个的物品放到n个地方有几种方法. 即解这个n元一次方程的非负整数解的个数$x_1+x_2+x_3+\dots+x_n=y$,其中0<=y<=m. 这个方程的非负整数解个数是个经典问题,可以+1转化正整数解的个数用插板法解决:$C_{y+n-1}^{n-1}=C_{y+n-1}^y$. 而0<=y<=m,最后的结果就是—— $$\sum_{i=0}^m C_{i+n-1}^i$$ $$C_{n-1}^0+C_{n}^1+C_{n+1}^2+\dots+C_{n-1…
Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family thinks that they have to solve a problem. They supp…
用于大组合数对p取模的计算. #include <cstdio> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> using namespace std; #define maxn 100010 typedef long long LL; LL m,n,p; LL Pow(LL a,LL b,LL mod) { LL ans=; while(…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5794 题意:让一个棋子从(1,1)走到(n,m),要求像马一样走日字型并只能往右下角走.里面还有r个障碍点不能经过或者到达,问有多少种走法可以走到(n,m). 思路:画个图可以发现走的点像一个斜着的杨辉三角.所以可以得到一个从点 i 走到点 j 的路径数是一个组合数. 大概就是长这样,杨辉三角的每个点的数如下. 1 1       1 1      2      1 1       3 …
大致意思就是求组合数C(n , m) % p的值, p为一个偶数 可以将组合数的n 和 m都理解为 p 进制的表示 n  = ak*p^k + a(k-1)*p^(k-1) + ... + a1*p + a0 m = bk*p^k + b(k-1)*p^(k-1) + ... + b1*p + b0 然后C(n,m)%p = C(ak , bk) * C(a(k-1) , b(k-1)) * ... * C(a1 , b1) * C(a0 , b0) % p 当然这其中出现 ai < bi的情况…
N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只能向右或向下走.并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 10007的结果.   Input 输入一个数N(2 <= N <= 10^9). Output 输出走法的数量 Mod 10007. Input示例 4 Output示例 10 明显是一道卡特兰数,推出ans = C(2*n-2,n-1) * 2 / n % MOD先让n--,ans = C(2*n,…
题目链接: 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…
原来一张图就就能证明:C(N,M)%P,p是素数. 简直太炫酷 先膜拜会 #include<iostream>#include<cstdio>#include<ctime>#include<cstring>#include<cstdlib>#include<vector>#define C 240#define TIME 10#define LL long longusing namespace std;LL PowMod(LL a,…
Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得到新数列A(1); 然后让Daxia求出数列A…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5794 多校这题转化一下模型跟cf560E基本一样,可以先做cf上的这个题. 题目让你求一个棋子开始在(1,1),只能像马一样走且往右下方走,不经过坏点,有多少种走法能到达(n,m)点. 比如n=6, m=5 有两个坏点,模型转换 如下图: 转换成简单模型之后,只要把棋子可能经过的坏点存到结构体中,按照x与y从小到大排序. dp[i]表示从起点到第i个坏点且不经过其他坏点的方案数. dp[i] = L…
题目链接:http://codeforces.com/contest/560/problem/E 给你一个n*m的网格,有k个坏点,问你从(1,1)到(n,m)不经过坏点有多少条路径. 先把这些坏点排序一下. dp[i]表示从(1,1)到第i个坏点且不经过其他坏点的路径数目. dp[i] = Lucas(x[i], y[i]) - sum(dp[j]*Lucas(x[i]-x[j], y[i]-x[j])) , x[j] <= x[i] && y[j] <= y[i] //到i…
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 LL; ; class LUCAS { //lucas求组合数C(n,k)%p LL F[M]; LL inv(LL a,LL mod) { ) ; return inv(mod%a,mod)*(mod-mod/a)%mod; } void init(LL p) { F[]=; ; i<=p; i++)…