今天下午刚起来眼睛就比较涨,,而且还有点恶心,唉,结果一直不在状态,而且这个题太坑了。。。。
点击此处即可传送 Hit 2255

Maybe ACMers of HIT are always fond of fibonacci numbers, because it is so beautiful. Don't you think so? At the same time, fishcanfly always likes to change and this time he thinks about the following series of numbers which you can guess is derived from the definition of fibonacci number. The definition of fibonacci number is: f(0) = 0, f(1) = 1, and for n>=2, f(n) = f(n - 1) + f(n - 2) We define the new series of numbers as below: f(0) = a, f(1) = b, and for n>=2, f(n) = p*f(n - 1) + q*f(n - 2),where p and q are integers. Just like the last time, we are interested in the sum of this series from the s-th element to the e-th element, that is, to calculate ."""" Great!Let's go! Input The first line of the input file contains a single integer t (1 <= t <= 30), the number of test cases, followed by the input data for each test case. Each test case contains 6 integers a,b,p,q,s,e as concerned above. We know that -1000 <= a,b <= 1000,-10 <= p,q <= 10 and 0 <= s <= e <= 2147483647. Output One line for each test case, containing a single interger denoting S MOD (10^7) in the range [0,10^7) and the leading zeros should not be printed. Sample Input
2
0 1 1 -1 0 3
0 1 1 1 2 3Sample Output
2
3

题目大意:
就是给你好几个数,分别表示什么意思,看题就行了;

解题思路:矩阵乘法,递推公式,

注意了,注意了,千万不要用全局变量
if(ans < 0)
ans += mod;
printf(“%lld\n”,ans);
}
return 0;
}
!!!!!!!

/*
2015 - 8 - 14 下午
Author: ITAK今天非常非常的不顺心啊。。。。今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 3;
const int mod = 1e7;
typedef long long LL;
typedef struct
{LL m[maxn][maxn];
} Matrix;
// LL a, b, s, e, q, p;千万不要用全局变量
Matrix P = {0,0,0,1,0,0,0,0,1};
Matrix I = {1,0,0,0,1,0,0,0,1};
Matrix matrix_mul(Matrix a, Matrix b)
{int i, j, k;Matrix c;for(i=0; i<maxn; i++){for(j=0; j<maxn; j++){c.m[i][j] = 0;for(k=0; k<maxn; k++){a.m[i][k] = (a.m[i][k]%mod + mod) % mod;b.m[k][j] = (b.m[k][j]%mod + mod) % mod;c.m[i][j] += (a.m[i][k] * b.m[k][j]) % mod;}c.m[i][j] = (c.m[i][j]%mod + mod) % mod;}}return c;
}Matrix quick_mod(LL m)
{Matrix ans = I, b = P;while(m){if(m & 1)ans = matrix_mul(ans, b);m >>= 1;b = matrix_mul(b, b);}return ans;
}
int main()
{int t;LL a, b, q, p, e, s;scanf("%d",&t);while(t--){Matrix tmp1, tmp2;LL ans, ans1, ans2;cin>>a>>b>>p>>q>>s>>e;P.m[0][0]=p;P.m[0][1]=q;P.m[2][0]=p;P.m[2][1]=q;if(s-2 > 0){tmp1 = quick_mod(s-2);ans1 = (b*tmp1.m[2][0])%mod + (a*tmp1.m[2][1])%mod + ((a+b)*tmp1.m[2][2])%mod;}else{if(s == 0)ans1 = 0;if(s == 1)ans1 = a;if(s == 2)ans1 = a + b ;}if(e-1 > 0){tmp2 = quick_mod(e-1);ans2 = (b*tmp2.m[2][0])%mod + (a*tmp2.m[2][1])%mod + ((a+b)*tmp2.m[2][2])%mod;}else{if(e == 0)ans2 = a;elseans2 = b+a;}ans1 = (ans1%mod+mod) % mod;ans2 = (ans2%mod+mod) % mod;//cout<<ans1<<" "<<ans2<<" ";ans = (ans2 - ans1 + mod) % mod;if(ans < 0)ans += mod;printf("%lld\n",ans);}return 0;
}

Hit 2255 Not Fibonacci相关推荐

  1. HIT 2060 Fibonacci Problem Again

    点击此处即可传送HIT 2060 As we know , the Fibonacci numbers are defined as follows: F(n) == {1 n==0||n==1{F( ...

  2. 斐波那契序列 Fibonacci

    [定理1] 标准Fibonacci序列(即第0项为0,第1项为1的序列)当N大于1时,一定有f(N)和f(N-1)互质 其实,结合"互质"的定义,和一个很经典的算法就可以轻松证明 ...

  3. 2012 winter training @HIT Day 2 解题报告

    今天第二天,主要练习二分和枚举.其实我突然发现,当做题突然卡主的时候,不妨想想今天练习的是什么内容-- 传送门http://acm.hit.edu.cn/hoj/contest/view?id=100 ...

  4. Fibonacci数列的java实现

    关于Fibonacci应该都比较熟悉,0,1,1,2,3..... 基本公式为f(n) = f(n-1) + f(n-2); f(0) = 0; f(1) =1; 方法1:可以运用迭代的方法实现: p ...

  5. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  6. Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

    參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...

  7. (C++)求Fibonacci数列的第n个数的两种方法

    方法一 #include<cstdio> #include<cmath>int main(){int n;scanf("%d",&n);if(n== ...

  8. H - Fibonacci POJ - 3070 (矩阵快速幂)

    H - Fibonacci POJ - 3070 (矩阵快速幂) Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and ...

  9. LeetCode 509. Fibonacci Number--Python解法

    题目地址:Fibonacci Number - LeetCode The Fibonacci numbers, commonly denoted F(n) form a sequence, calle ...

最新文章

  1. 自学python可以找到好的工作吗-学好python能找到好工作吗?
  2. JavaWEB_Tomcat安装与配置(J2EE Eclipse)
  3. ubuntu导入python的包_在ubuntu环境下怎么利用python将数据批量导入数据hbase
  4. 中交叉的线_表现力一绝!用交叉线构图拍出来的照片,竟然可以这么吸睛!
  5. android 弹起键盘把ui顶上去的解决办法
  6. 数据结构之线性表(附代码)
  7. PTA9、计算利率 (10 分)
  8. mysql root账号_修改mysql root账号密码
  9. python狗屁不通文章生成器_狗屁不通文章生成器,GitHub火爆的万字啰嗦文章瞬间生成...
  10. VirtualLab专题实验教程-1.超表面纳米柱及其相位分析
  11. HP OMEN品牌机配3090显卡,驱动,CUDA,Cudnn安装过程
  12. C语言作业解决,c语言作业9
  13. 打开微信开发者工具后无法显示文件的问题解决方案
  14. 企业数智化升级的四个“拦路虎”
  15. win10系统老显卡(AMD Radeon HD 8500M)驱动错误
  16. 新松机器人BG总裁高峰_新松机器人:做一个有价值的机器人企业!
  17. tomcat运行web项目报错:请求的资源[]不可用
  18. 浅析FPGA局部动态可重构技术
  19. LoRa Gateway 笔记 3.1.3 帮助程序 util_pkt_logger 进行 LoRa 空口抓包
  20. JVM性能优化之GC日志分析

热门文章

  1. 开度传感器专用测试仪采集编码器值的应用
  2. MyEclipse更改项目名称
  3. 人工智能在脊柱疾病中的应用综述
  4. RabbitMQ学习篇——(二)Rabbit安装完后,启动出现闪退问题解决!
  5. 201910010013(作业一)
  6. 基于Python制作的消消乐小游戏
  7. js平方计算器与猜数字游戏,计算从出生至今的天数
  8. 阿里干货课堂丨Android 高效的 Layout
  9. 【5G之道】第十六章:双连接
  10. 2020年度程序员新书/经典书TOP10