/* -*- coding: utf-8 -*- * * 147.cc: No.147 試験監督(2) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ typedef long long ll; const ll MOD = 1000000007; /* typedef */ typedef ll mat[2][2]; /* global variables */ /* subroutines */ void mulmat(const mat &a, const mat &b, mat &c) { // a * b -> c c[0][0] = (a[0][0] * b[0][0] + a[0][1] * b[1][0]) % MOD; c[0][1] = (a[0][0] * b[0][1] + a[0][1] * b[1][1]) % MOD; c[1][0] = (a[1][0] * b[0][0] + a[1][1] * b[1][0]) % MOD; c[1][1] = (a[1][0] * b[0][1] + a[1][1] * b[1][1]) % MOD; } void powmat(const mat &a, ll b, mat &c) { // a^b -> c c[0][0] = c[1][1] = 1, c[0][1] = c[1][0] = 0; mat t, a0; memcpy(a0, a, sizeof(a)); while (b > 0) { if ((b & 1) != 0) { mulmat(a0, c, t); memcpy(c, t, sizeof(t)); } mulmat(a0, a0, t); memcpy(a0, t, sizeof(t)); b >>= 1; } } ll powmod(ll a, ll n) { // a^n % MOD ll pm = 1; while (n > 0) { if ((n & 1) != 0) pm = (pm * a) % MOD; a = (a * a) % MOD; n >>= 1; } return pm; } /* main */ int main() { int n; cin >> n; ll mul = 1; while (n--) { ll ci; string ds; cin >> ci >> ds; ll di = 0; int dn = ds.size(); for (int i = 0; i < dn; i++) di = (di * 10 + (ds[i] - '0')) % (MOD - 1); mat a = {{0, 1}, {1, 1}}, c; powmat(a, ci, c); ll k = (c[0][0] * 1 + c[0][1] * 2) % MOD; ll kd = (k == 0) ? 0 : powmod(k, di); mul = (mul * kd) % MOD; //printf("%lld %lld -> %lld -> %lld\n", ci, di, k, kd); } printf("%lld\n", mul); return 0; }