#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. centos8.2-2004

    ~]# cat /etc/*leaseCentOS Linux release 8.2.2004 (Core)NAME="CentOS Linux"VERSION="8 ...

  2. Node.js入门(含NVM、NPM、NVM的安装)-(转载)

    Node.js的介绍 引擎 引擎的特性: JS的内核即引擎.因为引擎有以下特性: (1)转化的作用: 汽油柴油等等->动能 模板+数据--->页面 js引擎:js 代码--->机器码 ...

  3. idea配置javaweb项目(最新版)

    idea(最新版)配置javaweb项目 本篇文章使用Maven构建javaweb环境 最新版maven压缩包 链接:https://pan.baidu.com/s/1El7b3YzPTZX-7QRE ...

  4. SSTI漏洞-fastapi

    0x00 原理   SSTI漏洞全称服务器模板注入漏洞,服务器模板接收了用户输入的恶意代码,未经过滤便在服务端执行并通过渲染模板返回给用户,使得用户可以通过构造恶意代码在服务端执行命令. 0x01 c ...

  5. newbee-mall开源项目被慕课网拿去做课程,然后我毫不知情,这又是什么骚操作?

    万万没想到,这种事情会发生在我身上. 之前写过<开源囧事>系列而且已经写了四篇,四次开源囧事如下: <开源囧事(一)捅娄子了,写个bug被国家信息安全漏洞共享平台抓到了?> & ...

  6. 工作流Activiti框架中表单的使用!详细解析内置表单和外置表单的渲染

    Activiti中的表单 Activiti提供了一种方便而且灵活的方式在业务流程中以手工方式添加表单 对表单的支持有2种方式: 通过表单属性对内置表单进行渲染 通过表单属性对外置表单进行渲染 表单属性 ...

  7. Linux系统挂载NFS文件系统

    https://help.aliyun.com/document_detail/90529.html?spm=a2c4g.11186623.6.570.43212f30T5yM4w

  8. python 获取时间范围内日期列表

    python 获取时间范围内日期列表 import datetime def dateRange(beginDate, endDate): dates = [] dt = datetime.datet ...

  9. 给powershell增加类似于linux的alias功能

    给powershell增加类似于快捷方式的功能(类似于linux的alias) 首先执行 set-executionpolicy remotesigned 允许powershell执行脚本 然后执行e ...

  10. CVPR2020:视觉导航的神经拓扑SLAM

    CVPR2020:视觉导航的神经拓扑SLAM Neural Topological SLAM for Visual Navigation 论文地址: http://openaccess.thecvf. ...