今天下午刚起来眼睛就比较涨,,而且还有点恶心,唉,结果一直不在状态,而且这个题太坑了。。。。
点击此处即可传送 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. Android 游戏开发必备的基础知识
  2. 国内技术原创氛围为什么那么差?记EAWorld(普元)是如何靠“借鉴”产出原创文章的!
  3. 【TypeScript】字符串转义符序列
  4. 风控小白入门 | 关于评分模型验证的7大问题回答
  5. mysql5.7多源复制缺点_配置mysql5.7多源复制
  6. delphi 如何判断 socket 连接成功_Linux下的C++ socket编程实例
  7. Python如何上传文件?
  8. 黑马程序员python入门学习笔记
  9. 输入法 - 字母宽 窄 切换 - 全角 半角 的含义
  10. 纯HTML+CSS网页设计期末作业(个人网站)
  11. 5G牌照都发完了,那些传说中的5G手机Ready了吗?
  12. el-cascader数据绑定值原理之展平操作的算法
  13. JavaScript基础总结(1)
  14. 树莓派+opencv+百度aip实现人脸识别并发置邮箱
  15. 测试开发工作者日记:2020.6.10-6.11
  16. Android向服务器发送图片(一)
  17. Matlab中绘制颜色渐变曲线
  18. linux下 mysql的重启,启动,停止命令
  19. 可用的rtmp,rtsp,http网络流地址(2020-08-27更新)
  20. 基于GeoServer的电子地图系统说明

热门文章

  1. 拉线油门和电子油门的比较
  2. 巨人肩上的矮企鹅:QQ旋风为什么抄袭迅雷
  3. matlab指数积分函数,如何使用matlab拟合指数分布函数?
  4. AM2302(又称DHT22)温湿度传感器的使用及Proteus仿真(附源码)
  5. jsp留言本 jsp课程设计
  6. 起名~Java程序源码。
  7. 计算理论导引-图灵机
  8. Android平台手机UI应用开发——软件管理器
  9. 乐理01(音程、定调、和弦的构成、拓展)
  10. android动画背景,Android开发之背景动画简单实现方法