#include #include #include #include #include namespace nachia{ template struct StaticModint{ private: using u64 = unsigned long long; unsigned int x; public: using my_type = StaticModint; StaticModint() : x(0){} StaticModint(unsigned int v) : x(v){} unsigned int operator*() const { return x; } my_type& operator+=(const my_type& r){ auto t = x + r.x; if(t >= MOD) t -= MOD; x = t; return *this; } my_type operator+(const my_type& r) const { my_type res = *this; return res += r; } my_type& operator-=(const my_type& r){ auto t = x + MOD - r.x; if(t >= MOD) t -= MOD; x = t; return *this; } my_type operator-(const my_type& r) const { my_type res = *this; return res -= r; } my_type operator-() const { my_type res = *this; res.x = ((res.x == 0) ? 0 : (MOD - res.x)); return res; } my_type& operator*=(const my_type& r){ x = (u64)x * r.x % MOD; return *this; } my_type operator*(const my_type& r) const { my_type res = *this; return res *= r; } my_type pow(unsigned long long i) const { my_type a = *this, res = 1; while(i){ if(i & 1) res *= a; a *= a; i >>= 1; } return res; } my_type inv() const { return pow(MOD-2); } unsigned int val() const { return x; } static unsigned int get_mod() { return MOD; } my_type& operator/=(const my_type& r){ return operator*=(r.inv()); } my_type operator/(const my_type& r) const { return operator/(r.inv()); } }; } namespace nachia{ template struct MatrixModulo{ private: int h; int w; std::vector elems; public: MatrixModulo(int new_h, int new_w){ h = new_h; w = new_w; elems.assign(h * w, 0); } MatrixModulo(const MatrixModulo&) = default; int height() const { return h; } int width() const { return w; } typename std::vector::iterator operator[](int y){ return elems.begin() + (y * w); } typename std::vector::const_iterator operator[](int y) const { return elems.begin() + (y * w); } static MatrixModulo identity(int idx){ auto res = MatrixModulo(idx, idx); for(int i = 0; i < idx; i++) res[i][i] = 1; return res; } MatrixModulo operator*(const MatrixModulo& r) const { assert(w == r.h); auto res = MatrixModulo(h, r.w); for (int i=0; i=i; k--) g[j][k] -= g[j][i] * g[i][k]; } return ans; } int rank() const { MatrixModulo g = *this; int y = 0; for (int d=0; d=d; j--) g[i][j] -= g[i][d] * g[y][j]; y++; } return y; } MatrixModulo linear_equation() const { MatrixModulo g = *this; int y = 0; std::vector> det_var; std::vector rank_var; for (int d=0; d=d; j--) g[i][j] -= g[i][d] * g[y][j]; det_var.push_back(std::make_pair(d,y)); y++; } for (int i=y; i #include #include using namespace std; using i64 = long long; using u64 = unsigned long long; using i32 = int; using u32 = unsigned int; #define rep(i,n) for(int i=0; i<(n); i++) using m32 = nachia::StaticModint<1000000007>; using Mat = nachia::MatrixModulo; Mat pow_mat(Mat A, unsigned long long i) { Mat a = A, res = Mat::identity(A.height()); while(i){ if(i & 1) res = res * a; a = a * a; i >>= 1; } return res; } int main() { int A,B; cin >> A >> B; int N; cin >> N; Mat G0 = Mat::identity(3); G0[0][2] = B; G0[1][2] = A; Mat G1(3,3); G1[1][0] = 1; G1[2][1] = 1; Mat G01 = G0 * G1; rep(i,N){ u64 T; cin >> T; Mat res_mat = pow_mat(G01, T/2); if(T & 1) res_mat = res_mat * G0; m32 ans = 0; rep(a,2) rep(b,3) ans += res_mat[a][b]; cout << *ans << endl; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;