#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll;
const int N = 4;
int Mod;
int msize; struct Mat
{
int mat[N][N];
}; Mat operator *(Mat a, Mat b)
{
Mat c;
memset(c.mat, 0, sizeof(c.mat));
for(int k = 0; k < msize; ++k)
for(int i = 0; i < msize; ++i)
if(a.mat[i][k])
for(int j = 0; j < msize; ++j)
if(b.mat[k][j])
c.mat[i][j] = ((ll)a.mat[i][k] * b.mat[k][j] + c.mat[i][j])%Mod;
return c;
} Mat operator ^(Mat a, int k)
{
Mat c;
memset(c.mat,0,sizeof(c.mat));
for(int i = 0; i < msize; ++i)
c.mat[i][i]=1;
for(; k; k >>= 1)
{
if(k&1) c = c*a;
a = a*a;
}
return c;
} int main()
{
// freopen("in.txt", "r", stdin);
int t, a, b, n, m;
msize = 2;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d%d", &a, &b, &n, &m);
Mod = 1;
while(m--) Mod *= 10;
if(n == 0)
{
printf("%d\n", a%Mod);
continue;
}
Mat A;
A.mat[0][0] = 1, A.mat[0][1] = 1;
A.mat[1][0] = 1, A.mat[1][1] = 0;
A = A^(n-1);
printf("%d\n", (A.mat[0][0]*b + A.mat[0][1]*a)%Mod);
}
return 0;
}

UVA 10689 Yet another Number Sequence 矩阵快速幂 水呀水的更多相关文章

  1. UVA - 10689 Yet another Number Sequence 矩阵快速幂

                      Yet another Number Sequence Let’s define another number sequence, given by the foll ...

  2. Yet Another Number Sequence——[矩阵快速幂]

    Description Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recur ...

  3. HDU 1005 Number Sequence(矩阵快速幂,快速幂模板)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  4. HDU - 1005 Number Sequence 矩阵快速幂

    HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...

  5. HDU - 1005 -Number Sequence(矩阵快速幂系数变式)

    A number sequence is defined as follows:  f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) m ...

  6. Yet another Number Sequence 矩阵快速幂

    Let’s define another number sequence, given by the following function: f(0) = a f(1) = b f(n) = f(n ...

  7. SDUT1607:Number Sequence(矩阵快速幂)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1607 题目描述 A number seq ...

  8. Codeforces 392C Yet Another Number Sequence (矩阵快速幂+二项式展开)

    题意:已知斐波那契数列fib(i) , 给你n 和 k , 求∑fib(i)*ik (1<=i<=n) 思路:不得不说,这道题很有意思,首先我们根据以往得出的一个经验,当我们遇到 X^k ...

  9. CodeForces 392C Yet Another Number Sequence 矩阵快速幂

    题意: \(F_n\)为斐波那契数列,\(F_1=1,F_2=2\). 给定一个\(k\),定义数列\(A_i=F_i \cdot i^k\). 求\(A_1+A_2+ \cdots + A_n\). ...

随机推荐

  1. CPU 使用率 100% 怎么办

    CPU 使用率 100% 怎么办 独家号 码上实战 作者 flyhero原文链接 工作中遇到CPU使用率100%,不要慌,一起来找出原因并fix掉它. 记住这里大致流程,当线上突然遇到时,也不必手足无 ...

  2. Linux_WEB服务基础概念

    一.HTTPD简介 1️⃣:httpd是Apache超文本传输协议(HTTP) 服务器的主程序.被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池. 2️⃣:通常,httpd不应该 ...

  3. VIM 三种模式和常用命令

    引言 大数据开发工作中,周围的同事不是用 VIM 就是 Emacs,你要是用 UltraEdit 或 notepad++ 都不好意思跟人家打招呼...什么插件呀.语法高亮呀.拼写检查呀,能给它开的都给 ...

  4. mysql左连接和分组实例

    例: 需求:查询A表中的所有列,并查询A表中的数据(ID)在B表中出现的次数,然后按model排序,最后所有结果在一张表中展示 A表结构: B表结构: ini_device_policy表中id与in ...

  5. 信息学C++教程<-3->输入输出格式控制

    二进制输出整数 在计算机系统内的数据本身就是二进制 思考:在C++中,如何通过cout函数来输出二进制的数字呢? 所需库文件:1.iomanip //管理C++格式控制 ​ 2.bitset //二进 ...

  6. 深入剖析 MySQL 自增锁

    之前的文章把 InnoDB 中的所有的锁都介绍了一下,包括意向锁.记录锁...自增锁巴拉巴拉的.但是后面我自己回过头去看的时候发现,对自增锁的介绍居然才短短的一段. 其实自增锁(AUTO-INC Lo ...

  7. nignx反向代理web服务器的配置与使用

    一.为什么要用nignx反向代理 1.负载均衡 当一台服务器的单位时间内的访问量越大时,服务器压力就越大,大到超过自身承受能力时,服务器就会崩溃.为了避免服务器崩溃,让用户有更好的体验,我们通过负载均 ...

  8. 从Lombok到JSR-269

    前言 Lombok的出现帮助开发人员在开发工程中消除了大部分冗余代码:繁琐的get.set方法甚至建造者模式. Lombok的实现方式是什么呢? 新建一个测试类使用Lombok的Getter和Sett ...

  9. 机器学习PAI产品架构

    机器学习PAI产品架构 本文介绍PAI的产品架构. 如上图所示,PAI的业务架构分为五层: 基础设施层:包括CPU.GPU.FPGA及NPU. 计算引擎和容器服务层:包括MaxCompute.EMR. ...

  10. Jittor框架API

    Jittor框架API 这里是Jittor主模块的API文档,可以通过import jittor来获取该模块. classjittor.ExitHooks exc_handler(exc_type,  ...