/* -*- coding: utf-8 -*- * * 1810.cc: No.1810 RGB Biscuits - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MOD = 1000000007; /* typedef */ typedef long long ll; template struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) {} MI(long long _v): v(_v % MOD) {} MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } }; typedef MI mi; typedef mi mat[2][2]; /* global variables */ mat ma, mb; /* subroutines */ inline void initmat(mat a) { memset(a, 0, sizeof(mat)); } inline void unitmat(mat a) { a[0][0] = a[1][1] = 1; a[0][1] = a[1][0] = 0; } inline void copymat(const mat a, mat b) { memcpy(b, a, sizeof(mat)); } inline void mulmat(const mat a, const mat b, mat c) { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { c[i][j] = 0; for (int k = 0; k < 2; k++) c[i][j] += a[i][k] * b[k][j]; } } inline void powmat(const mat a, ll b, mat c) { mat s, t; copymat(a, s); unitmat(c); while (b > 0) { if (b & 1) { mulmat(c, s, t); copymat(t, c); } mulmat(s, s, t); copymat(t, s); b >>= 1; } } /* main */ int main() { int a, b, n; scanf("%d%d%d", &a, &b, &n); ma[0][0] = a, ma[0][1] = b; ma[1][0] = 1, ma[1][1] = 0; while (n--) { ll ti; scanf("%lld", &ti); powmat(ma, ti / 2, mb); mi rc = mb[0][0] + mb[0][1]; mi gc = mb[1][0] + mb[1][1]; mi bc = (ti & 1) ? rc * a + gc * b : 0; mi sum = rc + gc + bc; printf("%d\n", sum.v); } return 0; }