【HDU 2855】 Fibonacci Check-up (矩阵乘法)
2016-09-28 14:06
423 查看
Fibonacci Check-up
[align=left]Problem Description[/align]Every ALPC has his own alpc-number just like alpc12, alpc55, alpc62 etc.
As more and more fresh man join us. How to number them? And how to avoid their alpc-number conflicted?
Of course, we can number them one by one, but that’s too bored! So ALPCs use another method called Fibonacci Check-up in spite of collision.
First you should multiply all digit of your studying number to get a number n (maybe huge).
Then use Fibonacci Check-up!
Fibonacci sequence is well-known to everyone. People define Fibonacci sequence as follows: F(0) = 0, F(1) = 1. F(n) = F(n-1) + F(n-2), n>=2. It’s easy for us to calculate F(n) mod m.
But in this method we make the problem has more challenge. We calculate the formula
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<cmath> using namespace std; struct node { int a[5][5]; }t[5]; int n,m; void init() { t[0].a[1][1]=1;t[0].a[1][2]=1; t[0].a[2][1]=1;t[0].a[2][2]=2; } void mul(int x,int y,int z) { for(int i=1;i<=2;i++) for(int j=1;j<=2;j++) { t[2].a[i][j]=0; for(int k=1;k<=2;k++) t[2].a[i][j]=(t[2].a[i][j]+t[y].a[i][k]*t[z].a[k][j])%m; } t[x]=t[2]; } void get_un() { memset(t[1].a,0,sizeof(t[1].a)); for(int i=1;i<=2;i++) t[1].a[i][i]=1; } void qpow(int b) { get_un(); while(b) { if(b&1) mul(1,0,1); mul(0,0,0); b>>=1; } } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); init(); qpow(n); printf("%d\n",t[1].a[1][2]); } return 0; }
[HDU 2855]
2016-09-28 14:10:22
相关文章推荐
- hdu 2855 Fibonacci Check-up(矩阵乘法)
- HDU 2855 Fibonacci Check-up 矩阵
- hdu 2855 Fibonacci Check-up 矩阵+斐波那契通项公式
- hdu 2855 Fibonacci Check-up (矩阵)
- HDU - 2855 Fibonacci Check-up 矩阵快速幂
- HDU2855 Fibonacci Check-up 矩阵的应用
- HDU - 2855 Fibonacci Check-up 斐波那契矩阵
- hdu 2855 Fibonacci Check-up
- HDU 2855 Fibonacci Check-up 构造矩阵
- HDU - 2855 Fibonacci Check-up
- hdu 2855 Fibonacci Check-up
- hdoj 2855 Fibonacci Check-up 【打表找规律 + 矩阵快速幂】
- HDU 2855:Fibonacci Check-up_斐波拉契问题
- HDOJ 题目2855 Fibonacci Check-up(矩阵快速幂)
- [hdu2855][矩阵乘法]Fibonacci Check-up
- hdu 2855 Fibonacci Check-up【递推+矩阵快速幂】
- hdu 2855 Fibonacci Check-up(犀利的推导公式)
- hdu-2855 Fibonacci Check-up
- hdu 2855 Fibonacci Check-up
- hdu 2842 Chinese Rings(矩阵乘法+递推)