#include #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; struct Matrix { Matrix(int n) : size(n) { table.resize(n, vector(n, 0)); } Matrix operator*(const Matrix& mat) const { assert(mat.size == size); Matrix result(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { for (int k = 0; k < size; k++) { result.table[i][j] += table[i][k] * mat.table[k][j]; } } } return result; } const int size; vector> table; }; Matrix power(const Matrix& m, int n) { if (n == 1) { return m; } if (n % 2 == 1) { return m * power(m, n - 1); } else { const Matrix p = power(m, n / 2); return p * p; } } int main() { int N; cin >> N; Matrix m(N + 1); for (int i = 0; i <= N; i++) { for (int j = 1; j <= 6; j++) { int n = i + j; if (n > N) { n = 0; } m.table[i][n] += (long double)1.0 / 6; } } constexpr int rep = 10000; const Matrix result = power(m, rep); // show(result.table); cout << (long double)1.0 / result.table[0][N] - 1.0 << endl; return 0; }