Buge's Fibonacci Number Problem
Buge's Fibonacci Number Problem
Description
snowingsea is having Buge’s discrete mathematics lesson, Buge is now talking about the Fibonacci Number. As a bright student, snowingsea, of course, takes it as a piece of cake. He feels boring and soon comes over drowsy.
Buge,feels unhappy about him, he knocked at snowingsea’s head, says:”Go to solve the problem on the blackboard!”, snowingsea suddenly wakes up, sees the blackboard written :
snowingsea thinks a moment,and writes down:
snowingsea has a glance at Buge,Buge smiles without talking, he just makes a little modification on the original problem, then it becomes :
The modified problem makes snowingsea nervous, and he doesn't know how to solve it. By the way,Buge is famous for failing students, if snowingsea cannot solve it properly, Buge is very likely to fail snowingsea. But snowingsea has many ACM friends. So,snowingsea is asking the brilliant ACMers for help. Can you help him?
Input
The input consists of several test cases. The first line contains an integer T representing the number of test cases. Each test case contains 7 integers, they are f1, f2, a, b, k, n, m which were just mentioned above, where 0 < f1, f2, a, b, n, m < 1000 000 000, and 0 ≤ k < 50.
Output
Sample Input
3
1 1 1 1 1 2 100000
1 1 1 1 1 3 100000
1 1 1 1 1 4 100000
Sample Output
2
4
7
HINT
解题思路:就是一个简单的摸用算性质的应用,网上好多人用的是矩阵的一些性质,原谅我现代没好好学。
#include<iostream>
#define ll long long
using namespace std; ll f1, f2, a, b, k, n, m;
ll f3, t1, t2, t3;
ll sum = ; int main()
{
int T;
cin>>T;
while(T--)
{
cin>>f1>>f2>>a>>b>>k>>n>>m; f1 %= m;
f2 %= m;
t1 = f1;
for(int i = ; i < k; i ++)
{
t1 *= f1;
t1 %= m;
} t2 = f2;
for(int i = ; i < k; i ++)
{
t2 *= f2;
t2 %= m;
} sum = (( t1 + t2 ) % m);
sum %= m; for(int i = ; i < n; i++)
{
f3 = ( a * f2 + b * f1 ) % m;
t3 = f3;
for(int i = ; i < k; i ++)
{
t3 *= f3;
t3 %= m;
} sum += t3;
sum %= m; f1 = f2;
f2 = f3;
//cout<<sum<<endl;
} cout<<sum<<endl;
sum = ;
}
return ;
}
Buge's Fibonacci Number Problem的更多相关文章
- 【HDOJ】3509 Buge's Fibonacci Number Problem
快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. /* 3509 */ #inc ...
- [UCSD白板题] The Last Digit of a Large Fibonacci Number
Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...
- [UCSD白板题 ]Small Fibonacci Number
Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...
- 【leetcode】509. Fibonacci Number
problem 509. Fibonacci Number solution1: 递归调用 class Solution { public: int fib(int N) { ) return N; ...
- (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)
根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输 ...
- 求四百万以内Fibonacci(number)数列偶数结果的总和
又对啦...开心~~~~ 只是代码可能不符合PEP标准什么的... Each new term in the Fibonacci sequence is generated by adding the ...
- Fibonacci number
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- Algorithms - Fibonacci Number
斐波那契数列(Fibonacci Number)从数学的角度是以递归的方法定义的: \(F_0 = 0\) \(F_1 = 1\) \(F_n = F_{n-1} + F_{n-2}\) (\(n \ ...
- 【LEETCODE】44、509. Fibonacci Number
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
随机推荐
- iscrolljs 看API 回顾以前开发中失误
今天有空 细致的看看iscrolljs api 发现自己以前的几个失误是没看api造成的 失误1 页面a操作 影响了页面b的滚动条 api 解释: options.bindToWrapper The ...
- 查看IIS连接数
如果要想知道确切的当前网站IIS连接数的话,最有效的方法是通过windows自带的系统监视器来查看. 一.运行-->输入“perfmon.msc”. 二.在“系统监视器”图表区域里点击右键,然后 ...
- MongoDB使用小结:一些不常见的经验分享
最近一年忙碌于数据处理相关的工作,跟MongoDB打交道极多,以下为实践过程中的Q&A,后续会不定期更新补充. 另有<MongoDB使用小结:一些常用操作分享>,注:本文完成时Mo ...
- STM32之EXTI——外部中断
互联网的广大网友,大家早上中午晚上好.EXTI...故名思义..EX表外,出..I表示Intrrupt..所以合起来就是外部中断...说到这..我觉得我最近的六级水平(背单词)又进了一步,稍微自夸了下 ...
- java异常捕获
类ExampleA继承Exception,类ExampleB继承ExampleA. 有如下代码片断: try { throw new ExampleB("b") } catch(E ...
- linux软件包管理(下)
在vi配置文件的编写的时候我们发现#并不能注释掉一行的信息 那什么才是linux标准的注释信息呢 查看软件对应的软件包命令 rpm –ap| grep vim 大多example是需要的事例文档 双 ...
- IOS网络第二天 - 07-发送JSON给服务器
*************** #import "HMViewController.h" #import "MBProgressHUD+MJ.h" @inter ...
- Neil·Zou 语录三
1 人的大脑,假设100分成熟.那么每个人大脑达到100分的时间点不同.有些人因为外界因素在读书时就达到了,而有些人到工作后才达到.但很可惜,很多国人进入社会后就不学习了.所以说,工作后保持激情.好奇 ...
- php 验证(检查)日期格式是否正确
/** * 检查指定字符串是否为日期格式 年-月-日 * @param $date 日期字符串 * @return bool true 是日期格式 false 不是日期格式 */function va ...
- [UIScreen mainScreen].bounds.size.width 和self.view.frame.size.width的区别
self.view.frame.size.width在导航栏titleView计算frame时会出现宽度不准确的情况,布局出现问题,[UIScreen mainScreen].bounds.size. ...