HDU - 1005 Number Sequence (矩阵快速幂)
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n).
InputThe input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.
OutputFor each test case, print the value of f(n) on a single line.
Sample Input
1 1 3
1 2 10
0 0 0
Sample Output
2
5 原谅博主不会Markdown
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); struct Matrix{
int a[][];
}; Matrix mul(Matrix a,Matrix b){
Matrix ans;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
ans.a[i][j]=;
for(int k=;k<=;k++){
ans.a[i][j]+=a.a[i][k]*b.a[k][j];
}
ans.a[i][j]%=mod;
}
}
return ans;
} Matrix q_pow(Matrix a,int b){
Matrix ans ;
ans.a[][]=ans.a[][]=;
ans.a[][]=ans.a[][]=;
while (b){
if(b&){
ans=mul(ans,a);
}
b>>=;
a=mul(a,a);
}
return ans;
} int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); int A,B,n; while (scanf("%d%d%d",&A,&B,&n)!=EOF&&A&&B&&n){
Matrix exa;
if(n<=){printf("%d\n",);
continue;
}
exa.a[][]=A;
exa.a[][]=B;
exa.a[][]=;
exa.a[][]=; exa=q_pow(exa,n-);
printf("%d\n",(exa.a[][]+exa.a[][])%);
}
return ;
}
HDU - 1005 Number Sequence (矩阵快速幂)的更多相关文章
- HDU - 1005 Number Sequence 矩阵快速幂
HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...
- 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 ...
- 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 ...
- HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...
- UVA - 10689 Yet another Number Sequence 矩阵快速幂
Yet another Number Sequence Let’s define another number sequence, given by the foll ...
- Yet Another Number Sequence——[矩阵快速幂]
Description Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recur ...
- 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 ...
- SDUT1607:Number Sequence(矩阵快速幂)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1607 题目描述 A number seq ...
- hdu 5950 Recursive sequence 矩阵快速幂
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Codeforces 392C Yet Another Number Sequence (矩阵快速幂+二项式展开)
题意:已知斐波那契数列fib(i) , 给你n 和 k , 求∑fib(i)*ik (1<=i<=n) 思路:不得不说,这道题很有意思,首先我们根据以往得出的一个经验,当我们遇到 X^k ...
随机推荐
- vue cli3 子目录问题
在使用 vue-cli3 build的时候,使用非子目录需要在 vue.config.js 中添加如下代码: module.exports = { baseUrl: process.env.NODE_ ...
- MaxCompute 费用暴涨之存储压缩率降低导致SQL输入量变大
现象:同样的SQL,每天处理的数据行数差不多,但是费用突然暴涨甚至会翻数倍. 分析: 我们先明确MaxCompute SQL后付费的计费公式:一条SQL执行的费用=扫描输入量 ️ SQL复杂度 ️ 0 ...
- 基于MaxCompute的数仓数据质量管理
声明 本文中介绍的非功能性规范均为建议性规范,产品功能无强制,仅供指导. 参考文献 <大数据之路——阿里巴巴大数据实践>——阿里巴巴数据技术及产品部 著. 背景及目的 数据对一个企业来说已 ...
- javascript中数字的一些常规操作
1,禁止输入 - (减号.负号) // html <input type="number" class="no-negative"> // js $ ...
- Java“类”的内存分配_case1
- How To Move Or Rebuild A Lob Partition
How To Move Or Rebuild A Lob Partition [ID 761388.1] 改动时间 29-JUN-2010 类型 HOWTO 状 ...
- Spring读取配置文件,地址问题,绝对路径,相对路径
Spring在读取配置文件时,是相对于bin,或者WEB-INF的: “applicationContext.xml”就是找bin或WEB-INF及子文件夹下的文件: “/res/applicatio ...
- 洛谷 2403 [SDOI2010] 所驼门王的宝藏
题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为“先知”的Alpaca L. Sotomon是这个家族的领袖,外人也称其为“所驼门王”.所驼门王毕生致力于维护家族的安定与和谐, ...
- 微信接口开发报错invalid credential, access_token is invalid or not latest hint
微信接口凭证access_token一定要全局管理 我们的查酒后台集成了微信公众平台的客服API接口,不用登录微信公众号的后台就可以直接给用户发送消息.最近,运营的同事反馈,通过微信查酒,后台无法直接 ...
- python 多线程,tthread模块比较底层,而threading模块是对thread做了一些包装,multithreading
Python多线程详解 2016/05/10 · 基础知识 · 1 评论· 多线程 分享到:20 本文作者: 伯乐在线 - 王海波 .未经作者许可,禁止转载!欢迎加入伯乐在线 专栏作者. 1.多线程的 ...