题意:矩阵快速幂取模
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; long long mod; long long p[]={1,1,1,0}; void matrix(long long a[],long long b[],long long c[]){ long long q = a[0]*b[0] + a[1]*b[2]; long long w = a[0]*b[1] + a[1]*b[3]; long long e = a[2]*b[0] + a[3]*b[2]; long long r = a[2]*b[1] + a[3]*b[3]; c[0] = q%mod,c[1] = w%mod,c[2] = e%mod,c[3] = r%mod; } void pow_mod(long long a[],int n){ if (n > 1){ pow_mod(a,n/2); matrix(a,a,a); if (n % 2) matrix(a,p,a); } } int main(){ int n,m; while (scanf("%d%d",&n,&m) != EOF){ if (n >= 1){ mod = pow(2,m); long long a[10]; memcpy(a,p,sizeof(p)); pow_mod(a,n-1); printf("%lld\n",a[0]); } else printf("0\n"); } return 0; }