#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1000000007; // 行列の積 template vector > matrixProduct(const vector >& x, const vector >& y) { int a = x.size(); int b = x[0].size(); int c = y[0].size(); vector > z(a, vector(c, 0)); for(int i=0; i vector > matrixPower(const vector >& x, int k) { int n = x.size(); vector > y(n, vector(n, 0)); for(int i=0; i > z = x; while(k > 0){ if(k & 1) y = matrixProduct(y, z); z = matrixProduct(z, z); k >>= 1; } return y; } // 累乗、べき乗 long long power(long long a, long long b) { long long ret = 1; long long tmp = a; while(b > 0){ if(b & 1){ ret *= tmp; ret %= MOD; } tmp *= tmp; tmp %= MOD; b >>= 1; } return ret; } long long modular(const string& s, long long mod) { long long ret = 0; for(unsigned i=0; i> n; long long ret = 1; while(--n >= 0){ int c; string d; cin >> c >> d; vector > mat ={{1, 1}, {1, 0}}; mat = matrixPower(mat, c); long long x = mat[0][0] + mat[0][1]; long long y = modular(d, MOD - 1); ret *= power(x, y); ret %= MOD; } cout << ret << endl; return 0; }