#include #include #include #include #include #include #include #include #include #include using namespace std; #define MOD 1000000007 //[n*p] * [p*m] => [n*m] vector > multmat(vector > &A, vector > &B, int n, int p, int m){ vector > C(n, vector(m, 0LL)); for(int i=0; i > mat_pow(vector > A, long long k){ int n = A.size(); vector > ret(n, vector(n, 0LL) ); for(int i=0; i0LL){ if(k&1LL) ret = multmat(A,ret, n,n,n); A = multmat(A,A, n,n,n); k>>=1LL; } return ret; } // X = a*Y + b pair divide(string X, long long Y){ string a = ""; long long b = 0; for(int i=0; i 0) a.push_back(b/Y + '0'); }else{ a.push_back(b/Y + '0'); } b %= Y; } return {a,b}; } // string string_to_binary(string X, long long base){ string ret = ""; while(true){ auto tmp = divide(X, base); X = tmp.first; ret.push_back(tmp.second + '0'); //cerr << X.size() << " " << X[0] << endl; if(X.size() == 0){ break; } } reverse(ret.begin(), ret.end()); return ret; } long long mypow(long long X, long long k){ if(X==0) return 0; long long ret = 1; while(k>0){ if(k&1){ ret *= X; ret %= MOD; } X *= X; X %= MOD; k >>= 1LL; } return ret; } long long mypow(long long X, string k){ if(X==0) return 0; long long ret = 1; for(int i=k.size()-1; i>=0; i--){ if(k[i] == '1'){ ret *= X; ret %= MOD; } X *= X; X %= MOD; } return ret; } int main(){ int n; cin >> n; long long ans = 1; for(int i=0; i> c >> d; vector> A(2, vector(2, 1)); A[1][1] = 0; A = mat_pow(A, c+1); vector> B(2, vector(1, 0)); B[0][0] = 1; auto X = multmat(A,B, 2,2,1); long long x = X[0][0]; long long rem = divide(d, MOD-1).second; //string p = string_to_binary(d, 2); //cerr << x << " " << p << endl; ans *= mypow(x,rem)%MOD; ans %= MOD; } cout << ans << endl; return 0; }