2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774
----------------------------------------------------------------------------------------------------------------------
这题比较复杂,看这篇比较详细:http://blog.csdn.net/acdreamers/article/details/23039571
结论就是计算:
充分利用了快速幂及求逆元。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #define Mod 1000000009 #define ll long long using namespace std; #define N 100007ll fac[N],A[N],B[N];void init() {int i;fac[0] = 1;for(i=1;i<N;i++)fac[i] = fac[i-1]*i%Mod;A[0] = B[0] = 1;for(i=1;i<N;i++){A[i] = A[i-1]*691504013 % Mod;B[i] = B[i-1]*308495997 % Mod;} }ll fastm(ll n,ll k,ll MOD) {ll res = 1LL;n %= MOD;while(k){if(k&1LL)res = (res*n)%MOD;k >>= 1;n = n*n%MOD;}return res; }ll Inv(ll n,ll MOD) {return fastm(n,MOD-2,MOD); }int main() {int cs;ll n,k;init();ll ans,r;scanf("%d",&cs);while(cs--){scanf("%lld%lld",&n,&k);ans = 0;for(r=0;r<=k;r++){ll t = A[k-r]*B[r] % Mod;ll x = fac[k]; // k!ll y = fac[k-r]*fac[r] % Mod; // (k-r)!*(r)!ll c = x*Inv(y,Mod) % Mod; // c = C(k,r) = x/y = x*Inv(y)ll tmp = t*(fastm(t,n,Mod)-1)%Mod*Inv(t-1,Mod)%Mod; //t(t^n-1)/(t-1) = t(t^n-1)*Inv(t-1)if(t == 1)tmp = n%Mod;tmp = tmp*c%Mod;if(r&1LL) // (-1)^rans -= tmp;elseans += tmp;ans %= Mod;}//ans = ans*(1/sqrt(5))^kll m = Inv(383008016,Mod)%Mod;ans = ans*fastm(m,k,Mod)%Mod;ans = (ans%Mod+Mod)%Mod;printf("%lld\n",ans);}return 0; }
View Code
转载于:https://www.cnblogs.com/whatbeg/p/3836551.html
2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂相关推荐
- I-Matrix Power Series POJ - 3233 矩阵快速幂+分治
I-Matrix Power Series POJ - 3233 矩阵快速幂+分治 Problem Description Given a n × n matrix A and a positive ...
- SDNU 1062.Fibonacci(矩阵快速幂)
Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. I ...
- poj - problem 3070 Fibonacci 【矩阵 +快速幂】
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13732 Accepted: 9728 Descri ...
- POJ3070 Fibonacci【矩阵快速幂】
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20098 Accepted: 13850 Descripti ...
- POJ3070 Fibonacci(矩阵快速幂)
用矩阵快速幂求fibonacci序列的第n项. /* *********************************************** Author :devil Created Tim ...
- 2014 Super Training #8 C An Easy Game --DP
原题:ZOJ 3791 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3791 题意:给定两个0-1序列s1, s2,操作t ...
- 2014 Super Training #10 D 花生的序列 --DP
原题: FZU 2170 http://acm.fzu.edu.cn/problem.php?pid=2170 这题确实是当时没读懂题目,连样例都没想通,所以没做了,所以还是感觉这样散漫的做不好,有些 ...
- Fibonacci数列 矩阵快速幂
点击打开链接 问题 A: 一道简单的Fibonacci 时间限制: 1 Sec 内存限制: 32 MB 题目描述 有如下数列:F(0) = 7, F(1) = 11, F(n) = F(n - 1) ...
- 2019牛客多校第九场AThe power of Fibonacci(广义BM)
2019牛客多校第九场AThe power of Fibonacci(广义BM) 题目大意 求斐波那契数列m次方的前n项和 解题思路 显然,斐波那契的m次方前缀和依然是线性递推,因此考虑用exBM求解 ...
最新文章
- 5.Collection集合 List集合 泛型
- antd Tree组件中,自定义右键菜单
- PHP 两个页面跳转,session会失效?
- Java多线程(二)之Atomic:原子变量与原子类
- php取mysql某列的值,php – 获取MYSQL中某些列为null的表中的值
- mysql c接口_mysql C语言API接口及实例
- 鼎立测试软件能锁网吗,路测软件鼎利通信Pioneer操作培训PPT(ET128).ppt
- 采用esxcli命令操作esxi主机防火墙
- sql 分组排序语句顺序
- 十个值得所有极客收藏的网站
- 从10个经典工业设计案例,来看什么是工业设计
- 与小卡特一起学python 豆瓣_《父与子的编程之旅:与小卡特一起学Python》
- 解决tuple index out of range
- 计算机职业生涯规划书素材,职业生涯规划书封面素材
- 一次ORA-3136的处理
- python selenium 不打开浏览器_selenium+python自动化测试--解决无法启动IE浏览器及报错问题...
- 屏蔽eslint检测某项报错
- 机器人简化图画手绘图_机器人简笔画画法图片欣赏
- 【算法】重新排序数组中正数和负数
- Nginx防止恶意域名解析