//// 9 % #include <cstdio> #include <iostream> using namespace std; const long long mod = 1e9 + 7; long long a, b, c, d, n; struct Mat {   long long a[4][4];   Mat() {     for(int i = 0; i < 4; i++)       for(int j = 0; j < 4; j++) a[i][j] = 0LL;   }   void I() {     a[0][0] = a[1][1] = a[2][2] = a[3][3] = 1LL;   } }; Mat operator*(const Mat& a, const Mat& b) {   Mat ret;   for(int i = 0; i < 4; i++) {     for(int j = 0; j < 4; j++) {       for(int k = 0; k < 4; k++) {         ret.a[i][j] += (a.a[i][k] * b.a[k][j]) % mod;         ret.a[i][j] %= mod;       }     }   }   return ret; } Mat quick_pow(Mat a, long long b) {   Mat ret;   ret.I();   while(b > 0) {     if (b&1) ret = ret * a;     a = a * a;     b >>= 1;   }   return ret; } int main() {   Mat M;   M.a[0][3] = 1;   M.a[1][0] = 1; M.a[1][3] = 1;   M.a[2][1] = 1; M.a[2][3] = 0;   M.a[3][2] = 1; M.a[3][3] = 1;   cin >> a >> b >> c >> d >> n;   a %= mod; b %= mod; c %= mod; d %= mod;   long long ans = -1;   if(n == 1) {     ans = a;   }   else if(n == 2) {     ans = b;   }   else if(n == 3) {     ans = c;   }   else if(n == 4) {     ans = d;   }   else {     Mat x;     x = quick_pow(M, n-4);     ans = 0LL;     ans += (a * x.a[0][3]) % mod; ans %= mod;     ans += (b * x.a[1][3]) % mod; ans %= mod;     ans += (c * x.a[2][3]) % mod; ans %= mod;     ans += (d * x.a[3][3]) % mod; ans %= mod;   }   cout << ans % mod << endl; }
点赞 5

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务