[xdoj1227]Godv的数列(crt+lucas)
解题关键:1001=7*11*13,模数非常小,直接暴力lucas。递归次数几乎为很小的常数。最后用中国剩余定理组合一下即可。
模数很小时,一定记住lucas定理的作用
http://acm.xidian.edu.cn/problem.php?id=1227
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
const int mod=;
inline int read(){
char k=;char ls;ls=getchar();for(;ls<''||ls>'';k=ls,ls=getchar());
int x=;for(;ls>=''&&ls<='';ls=getchar())x=(x<<)+(x<<)+ls-'';
if(k=='-')x=-x;return x;
}
int a[maxn],fac[][maxn],inv[][maxn];
ll mod_pow(ll x,ll n,ll p){
ll res=;
while(n){
if(n&) res=res*x%p;
x=x*x%p;
n>>=;
}
return res;
}
ll comb(ll n,ll m,ll p){
if(n==m) return ;
if(n<m) return ;
if(m>n-m) m=n-m; ll tn=,tm=;
while(m){
tn=tn*n%p;
tm=tm*m%p;
n--,m--;
}
return tn*mod_pow(tm,p-,p)%p;
}
ll lucas(ll n,ll m,ll p){
ll res=;
while(m){
res=res*comb(n%p,m%p,p)%p;
n/=p;
m/=p;
}
return res;
}
int main(){
int t,n;
t=read();
while(t--){
n=read();
for(int i=;i<=n;i++) a[i]=read()%;
int ans=,t1,t2,tans,t3;
for(int i=;i<=n;i++){
t3=lucas(n-,i-,);
t2=lucas(n-,i-,);
t1=lucas(n-,i-,);
tans=(*t1+*t2+*t3)%;
ans=(ans+tans*a[i])%;
}
printf("%d\n",ans);
}
return ;
}
[xdoj1227]Godv的数列(crt+lucas)的更多相关文章
- CRT, lucas及其扩展形式
CRT, lucas及其扩展形式 exgcd int exgcd(int a, int b, int &x, int &y) { if (b == 0) return a, x = 1 ...
- luogu 2480 古代猪文 数论合集(CRT+Lucas+qpow+逆元)
一句话题意:G 的 sigma d|n C(n d) 次幂 mod 999911659 (我好辣鸡呀还是不会mathjax) 分析: 1.利用欧拉定理简化模运算 ,将上方幂设为x,则x=原式mod ...
- HDU 5446——Unknown Treasure——————【CRT+lucas+exgcd+快速乘+递推求逆元】
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 o ...
- Fibonacci 数列和 Lucas 数列的性质、推论及其证明
Fibonacci 数列 设f(x)=1,x∈{1,2}=f(x−1)+f(x−2),x∈[3,∞)\begin{aligned}f(x)&=1,\quad\quad\quad\quad\qu ...
- [NOIP模拟测试7]visit 题解(组合数学+CRT+Lucas定理)
Orz 因为有T的限制,所以不难搞出来一个$O(T^3)$的暴力dp 但我没试 据说有30分? 正解的话显然是组合数学啦 首先$n,m$可能为负,但这并没有影响, 我们可以都把它搞成正的 即都看作向右 ...
- HDU 5446 CRT+Lucas+快速乘
Unknown Treasure Problem Description On the way to the next secret treasure hiding place, the mathem ...
- SDOI2019 省选前模板整理
目录 计算几何✔ DP 斜率优化✔ 四边形不等式✔ 轮廓线DP✘ 各种分治 CDQ分治✔ 点分治✔ 整体二分✔ 数据结构 线段树合并✔ 分块✔ K-D Tree LCT 可持久化Trie✔ Splay ...
- bzoj1951
CRT+LUCAS+费马小定理+拓展欧拉定理 幂指数太大了怎么办?欧拉定理,n太大了怎么办?上lucas,模数太大了怎么办?上crt.然后就好了,唯一注意的是要用拓展欧拉定理,n%phi(p)+phi ...
- 「ExLucas」学习笔记
「ExLucas」学习笔记 前置芝士 中国剩余定理 \(CRT\) \(Lucas\) 定理 \(ExGCD\) 亿点点数学知识 给龙蝶打波广告 Lucas 定理 \(C^m_n = C^{m\% m ...
随机推荐
- 动态内存分配(Dynamic memory allocation)
下面的代码片段的输出是什么?为什么? 解析:这是一道动态内存分配(Dynamic memory allocation)题. 尽管不像非嵌入式计算那么常见,嵌入式系统还是有从堆(heap)中动态分 ...
- SSIS
http://www.cnblogs.com/codefish/category/557802.html
- Angular入门(一) 环境配置
angular/cli 安装 ♦ npm uninstall -g angular-cli /cnpm install -g angular-cli ※采用npm安装失败: Missing write ...
- 在pycharm中误删了Python文件,怎么办,挺急的?
1.今天在操作的时候,误删了文件,怎么办? (1)找到删除的上一级文件=>右键,找到Local History=>Show History (2),打开之后,双击左边的恢复时间内容,在右边 ...
- python3用pdfminer3k在线读取pdf文件
import importlib import sys import random from urllib.request import urlopen from urllib.request imp ...
- web tools for sublime
Your code editor is your main development tool; you use it to write and save lines of code. Write be ...
- Contiki 2.7 Makefile 文件(二)
二.Makefile.include 1.第一部分 (1) ifndef CONTIKI ${error CONTIKI not defined! You must specify where Con ...
- 1--单独使用jdbc开发问题总结
1.数据库连接,使用时就创建,不使用立即释放,对数据库进行频繁连接开启和关闭,造成数据库资源浪费,影响 数据库性能. 设想:使用数据库连接池管理数据库连接. 2.将sql语句硬编码到java代码中,如 ...
- 使用C语言解析URL
1. [代码]容易写成自己输入URL,这里测试一个例子 #include <stdio.h>#include <stdlib.h>#include <string ...
- 分享知识-快乐自己:Oracle SQL语法汇总
--删除重复值-保留重复值最大的编号 delete from emp where rowid in( select rowid from emp where rowid not in( select ...