ZOJ 3774 二次剩余
题意:简单粗暴,求菲波那契数列每个数的m次的前n项和模1e9+7
思路:斐波那契通项式
, 注意到有很多根号5,求二次剩余为5模1e9+7的解,显然我们可以直接找一个(383008016),然后拿来替代根号5,然后优化下,把中括号中共轭的两部分预处理下,然后由于是外部的一个指数m,从1枚举到m,来求二项式定理的每项系数,再用个逆元就好了。人家的校赛题(
/** @Date : 2017-03-18-15.39
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include<bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const LL mod = 1e9 + 9;
const LL trem = 383008016;
LL fac[N], le[N], ri[N]; LL fpow(LL a, LL n)
{
LL res = 1;
while(n > 0)
{
if(n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
} LL Inv(LL x)
{
return fpow(x, mod - 2);
} void init()
{
LL tinv = Inv(2); fac[0] = 1;
le[0] = ri[0] = 1;
LL l = ((1 + trem + mod)%mod) * tinv % mod;
LL r = ((1 - trem + mod)%mod) * tinv % mod;
for(LL i = 1; i < N; i++)
fac[i] = fac[i - 1] * i % mod;
for(int i = 1; i < N; i++)
{
le[i] = le[i - 1] * l % mod;
ri[i] = ri[i - 1] * r % mod;
//cout << le[i] <<" " << ri[i] << endl;
}
}
int T;
LL n, k;
int main()
{
init();
cin >> T;
while(T--)
{
scanf("%lld%lld", &n, &k);
LL ans = 0;
for(int i = 0; i <= k; i++)
{
LL flag = 1;
if((k - i) % 2)
flag = -1;
LL t = le[i] * ri[k - i] % mod;
LL d = fac[k - i] * fac[i] % mod;
LL c = fac[k] * Inv(d) % mod;
LL x = (t * (1 - fpow(t, n)) % mod) * Inv(1 - t) % mod;
if(t == 1)
x = n % mod;
ans = (ans + flag * c * x ) % mod;
ans = (ans + mod) % mod;
//cout << t << endl;
}
ans = (ans * fpow(Inv(trem) % mod, k) + mod) % mod;
printf("%lld\n", ans);
}
return 0;
}
ZOJ 3774 二次剩余的更多相关文章
- [zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)
Power of Fibonacci Time Limit: 5 Seconds Memory Limit: 65536 KB In mathematics, Fibonacci numbe ...
- ZOJ 3774 Fibonacci的K次方和
In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the f ...
- Fibonacci数列的幂和 zoj 3774
题目大意: 求斐波那契数列前n项的k次幂和 Mod 1000000009. n<=1e18, k<=1e5 这题的k比较大,所以不能用矩阵乘法来递推.学到了新姿势... http ...
- [hdu 4959]Poor Akagi 数论(卢卡斯数,二次域运算,等比数列求和)
Poor Akagi Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- 1.2Linux下C语言开发基础(学习过程)
===============第二节 Linux下C语言开发基础=========== ********************** 重要知识点总结梳理********************* 一 ...
- MySQL的课堂的实践
MySQL的课堂的实践 基本认识 如今的数据库有几种是主流,分别是:Oracle Database.Informix.SQL Server.PostgreSQL.MySQL等,我们现在学习的MySQL ...
- 继承&成员函数&覆盖
//成员函数. /* 当子父类中出现成员函数一模一样的情况,会运行子类的函数. 这种现象,称为覆盖操作.这时函数在子父类中的特性. 函数两个特性: 1,重载.同一个类中.overload 2,覆盖.子 ...
- 给新建的kvm虚拟机创建网络接口
(一)首先必须创建网卡连接桥接口的启动脚本和停止脚本,其中脚本中的 $1:表示为虚拟机的网卡的右边接口,这两个脚本就是讲虚拟机的网卡的右边接口接在网桥上,实现桥接模型 # 1:/etc/qem ...
- java.lang.NoClassDefFoundError: Lcom/opensymphony/xwork2/util/logging/Logger tomcat6 启动错误
用tomcat6启动时,出现下面的错误Java.lang.NoClassDefFoundError: Lcom/opensymphony/xwork2/util/logging/Logger; Cau ...
- web.py 笔记
1.涉及到id=‘id’的情况,需要加入 vars=locals() ,因为id在python里有id() 函数 db.delete('entries', where = 'id = $id', ...
- PHP面向对象之接口
接口(interface)技术 什么是接口? 先看抽象类: abstract class 类名 { 属性1: 属性2: ..... 非抽象方法1: 非抽象方法2: ...... 抽象方法1: 抽 ...
- 解决Lenovo(ldeapad)笔记本F1-F12功能键操作无效的问题
1.操作条件:Lenovo笔记本自带的“一键恢复”按钮 2.操作方法:上下键为切换选项,回车键(Enter)为确定选择 (1)在笔记本电脑关机状态下,使用曲别针或其他物件按下笔记本自带的“一键恢复按钮 ...
- caffe框架下目标检测——faster-rcnn实战篇操作
原有模型 1.下载fasrer-rcnn源代码并安装 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 1) ...
- MachineLearning ---- lesson 1
该博文系列是Andrew NG教授的课程笔记,有兴趣的朋友可以在Coursera或者网易公开课上找到该课程. Supervised Learning 下图是一个监督学习回归分析的例子.该图旨在预测房价 ...