#line 1 "1073_matrix_static.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/1073" #include // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sat Jun 6 01:52:00 JST 2020 **/ #define CALL_FROM_TEST #line 1 "/Users/knshnb/competitive_programming/competitive_library/src/Math/MatrixStatic.hpp" template struct Matrix { std::array, size> A; Matrix() {} Matrix(const std::array, size> &A_) : A(A_) {} static Matrix eye() { Matrix mat{}; for (int i = 0; i < size; i++) mat[i][i] = 1; return mat; } std::array &operator[](int k) { return A[k]; } const std::array &operator[](int k) const { return (A[k]); } Matrix &operator+=(const Matrix &B) { for (int i = 0; i < A.size(); i++) for (int j = 0; j < A[0].size(); j++) A[i][j] += B[i][j]; return *this; } Matrix &operator-=(const Matrix &B) { for (int i = 0; i < A.size(); i++) for (int j = 0; j < A[0].size(); j++) A[i][j] -= B[i][j]; return *this; } Matrix &operator*=(const Matrix &B) { std::array, size> C{}; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) for (int k = 0; k < size; k++) C[i][j] += A[i][k] * B[k][j]; std::swap(A, C); return *this; } Matrix operator+(const Matrix &B) const { return Matrix(*this) += B; } Matrix operator-(const Matrix &B) const { return Matrix(*this) -= B; } Matrix operator*(const Matrix &B) const { return Matrix(*this) *= B; } std::array operator*(const std::array &x) const { std::array ret{}; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) ret[i] += A[i][j] * x[j]; return ret; } }; #line 1 "/Users/knshnb/competitive_programming/competitive_library/src/Math/ModInt.hpp" template T pow(T x, long long n, const T UNION = 1) { T ret = UNION; while (n) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } /// @docs src/Math/ModInt.md template struct ModInt { int x; static int runtime_mod; static std::unordered_map to_inv; // テンプレート引数が負のときは実行時ModInt static int mod() { return Mod < 0 ? runtime_mod : Mod; } static void set_runtime_mod(int mod) { static_assert(Mod < 0, "template parameter Mod must be negative for runtime ModInt"); runtime_mod = mod; to_inv.clear(); } ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod() + mod()) >= mod()) x -= mod(); } ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod()) x -= mod(); return *this; } ModInt& operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod(); return *this; } ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod(); return *this; } ModInt& operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod(); return *this; } ModInt operator-() const { return -x < 0 ? mod() - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return to_inv.count(this->x) ? to_inv[this->x] : (to_inv[this->x] = pow(*this, mod() - 2).x); } friend std::ostream& operator<<(std::ostream& s, ModInt a) { s << a.x; return s; } friend std::istream& operator>>(std::istream& s, ModInt& a) { long long tmp; s >> tmp; a = ModInt(tmp); return s; } friend std::string to_string(ModInt a) { return std::to_string(a.x); } }; template std::unordered_map ModInt::to_inv; template int ModInt::runtime_mod; #ifndef CALL_FROM_TEST using mint = ModInt<1000000007>; #endif #line 20 "1073_matrix_static.test.cpp" #undef CALL_FROM_TEST using mint = ModInt<1000000007>; signed main() { Int n; std::cin >> n; std::array x{}; x[0] = 1; Matrix A{}; REP(j, 6) A[0][j] = mint(1) / 6; REP(i, 1, 6) A[i][i - 1] = 1; auto ret = pow(A, n, Matrix::eye()) * x; std::cout << ret[0] << std::endl; }