题目链接 ->扩展Lucas //求C_n^k%m #include <cstdio> typedef long long LL; LL FP(LL x,LL k,LL p) { LL t=1ll; for(; k; k>>=1,x=x*x%p) if(k&1) t=t*x%p; return t; } void Exgcd(LL a,LL b,LL &x,LL &y) { if(!b) x=1ll, y=0ll; else Exgcd(b,a%b,y…
J. Ceizenpok’s formula time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output Dr. Ceizenp'ok from planet i1c5l became famous across the whole Universe thanks to his recent discovery — the Ceizenpok’s formul…
默默敲了一个下午,终于过了, 题目传送门 扩展Lucas是什么,就是对于模数p,p不是质数,但是不大,如果是1e9这种大数,可能没办法, 对于1000000之内的数是可以轻松解决的. 题解传送门 代码完全手写,直接写了扩展的中国剩余定理(普通的不会写) 题意:给你n,m,p 求C(n,m)%p #include<cstring> #include<cmath> #include<cstdio> #include<iostream> #include<a…
Description 题库链接 求 \[C_n^m \mod p\] \(1\leq m\leq n\leq 10^{18},2\leq p\leq 1000000\) Solution 一般的 \(Lucas\) 是在模数 \(p\) 是质数的条件下适用的.我们来考虑 \(p\) 不是质数的条件. 我们对 \(p\) 进行唯一分解,记 \(p=p_1^{k_1}p_2^{k_2}\cdots p_q^{k_q}\) ,由于形同 \(p_i^{k_i}\) 的部分是互质的,显然我们可以用 \(…
拓展Lucas #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<vector> #define MAXN 100000+10 #define ll long long #define pb push_back #define ft first #define sc second #define mp make_pair using…
http://codeforces.com/gym/100633/problem/J 其实这个解法不难学的,不需要太多的数学.但是证明的话,我可能给不了严格的证明.可以看看这篇文章 http://www.cnblogs.com/jianglangcaijin/p/3446839.html   膜拜 #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include…
J. Ceizenpok’s formula time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dr. Ceizenp'ok from planet i1c5l became famous across the whole Universe thanks to his recent discovery — the Ceizenp…
传送门 [题意]: 求C(n,k)%m,n<=108,k<=n,m<=106 [思路]: 扩展lucas定理+中国剩余定理    #include<cstdio> using namespace std; typedef long long ll; ll n,m,MOD,ans; ll fpow(ll a,ll p,ll mod){ ll res=; ,a=a*a%mod) ) res=res*a%mod; return res; } void exgcd(ll a,ll b…
http://codeforces.com/gym/100633/problem/J Lucas定理P不是质数裸题 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; inline ll read(){ ,f=; ;c=get…
4830: [Hnoi2017]抛硬币 题意:A投a次硬币,B投b次硬币,a比b正面朝上次数多的方案数,模\(10^k\). \(b \le a \le b+10000 \le 10^{15}, k \le 9\) 几乎一下午和一晚上杠这道题...中间各种翻<具体数学>各种卡常 有两种做法,这里只说我认为简单的一种. 题目就是要求 \[ \sum_{i=0}^a \sum_{j=0}^b [i>j] \binom{a}{i} \binom{b}{j} \] 化一化得到 \[ \sum_{…