博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
矩阵快速幂
阅读量:3954 次
发布时间:2019-05-24

本文共 1440 字,大约阅读时间需要 4 分钟。

矩阵快速幂,看着听高深,其实就是字面意思,矩阵的快速幂,再说清楚点就是矩阵的幂运算,很好理解,但这涉及到矩阵的乘法,先来矩阵的乘法:上模板:

const int N=2;int tmp[N][N];void multi(int a[][N],int b[][N],int n){    memset(tmp,0,sizeof tmp);    for(int i=0;i
>=1; }}

Let’s define another number sequence, given by the following function: f(0) = a f(1) = b f(n) = f(n − 1) + f(n − 2), n > 1 When a = 0 and b = 1, this sequence gives the Fibonacci Sequence. Changing the values of a and b, you can get many different sequences. Given the values of a, b, you have to find the last m digits of f(n). Input The first line gives the number of test cases, which is less than 10001. Each test case consists of a single line containing the integers a b n m. The values of a and b range in [0, 100], value of n ranges in [0, 1000000000] and value of m ranges in [1, 4]. Output For each test case, print the last m digits of f(n). However, you should NOT print any leading zero.

Sample Input

4

0 1 11 3

0 1 42 4

0 1 22 4

0 1 21 4

Sample Output

89

4296

7711

946

给定一个斐波那契数列的前两位,求后m位。

å¨è¿éæå¥å¾çæè¿°

#include
#include
#include
#include
#include
using namespace std;#define ll long longll mod;const int N=2;int tmp[N][N];void multi(int a[][N],int b[][N],int n){ memset(tmp,0,sizeof tmp); for(int i=0;i
>=1; }}int main(){ ios::sync_with_stdio(false); int t; cin>>t; while(t--) { int a,b,m; ll n; cin>>a>>b>>n>>m; mod=1; while(m--) { mod*=10; } if(n==0) { cout<
<

 

转载地址:http://qvyzi.baihongyu.com/

你可能感兴趣的文章
Android LOG机制流程图
查看>>
如何在JNI中抛异常
查看>>
Android应用程序的完全退出
查看>>
Task和Activity相关的一些属性
查看>>
JAVA系统属性之user.home
查看>>
Android代码截屏
查看>>
Android中打印代码的调用层次
查看>>
成功者十三个价值连城的习惯
查看>>
特别成功的人会做6件事
查看>>
Android: 用jni 获取MAC地址
查看>>
字符串列表的C语言实现:c_strlist
查看>>
客户沟通的方式:礼貌待客沟通方式,技巧推广沟通方式,个性服务沟通方式
查看>>
用弹性工作制留住员工
查看>>
知识=经验×反思2
查看>>
领导者如何发现关键问题
查看>>
学习无为领导力
查看>>
卓越领导看过程
查看>>
领导力与各种循环挑战
查看>>
达成谈判协议 - 避免操之过急
查看>>
销售人说话“十大忌”
查看>>