#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=2e9+1; const ll INF=4e18; const ll dy[8]={-1,0,1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } namespace NTT { //MOD9のNTT auto c=NTT::mul(a,b)で受け取り。 std::vector tmp; size_t sz = 1; inline ll powMod(ll n, ll p, ll m) { ll res = 1; while (p) { if (p & 1) res = res * n % m; n = n * n % m; p >>= 1; } return res; } inline ll invMod(ll n, ll m) { return powMod(n, m - 2, m); } ll extGcd(ll a, ll b, ll &p, ll &q) { if (b == 0) { p = 1; q = 0; return a; } ll d = extGcd(b, a%b, q, p); q -= a/b * p; return d; } pair ChineseRem(const vector &b, const vector &m) { ll r = 0, M = 1; for (int i = 0; i < (int)b.size(); ++i) { ll p, q; ll d = extGcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return make_pair(0, -1); ll tmp = (b[i] - r) / d * p % (m[i]/d); r += M * tmp; M *= m[i]/d; } return make_pair((r+M+M)%M, M); } template struct NTTPart { static std::vector ntt(std::vector a, bool inv = false) { size_t mask = sz - 1; size_t p = 0; for (size_t i = sz >> 1; i >= 1; i >>= 1) { auto& cur = (p & 1) ? tmp : a; auto& nex = (p & 1) ? a : tmp; ll e = powMod(PrimitiveRoot, (Mod - 1) / sz * i, Mod); if (inv) e = invMod(e, Mod); ll w = 1; for (size_t j = 0; j < sz; j += i) { for (size_t k = 0; k < i; ++k) { nex[j + k] = (cur[((j << 1) & mask) + k] + w * cur[(((j << 1) + i) & mask) + k]) % Mod; } w = w * e % Mod; } ++p; } if (p & 1) std::swap(a, tmp); if (inv) { ll invSz = invMod(sz, Mod); for (size_t i = 0; i < sz; ++i) a[i] = a[i] * invSz % Mod; } return a; } static std::vector mul(std::vector a, std::vector b) { a = ntt(a); b = ntt(b); for (size_t i = 0; i < sz; ++i) a[i] = a[i] * b[i] % Mod; a = ntt(a, true); return a; } }; std::vector mul(std::vector a, std::vector b) { size_t m = a.size() + b.size() - 1; sz = 1; while (m > sz) sz <<= 1; tmp.resize(sz); a.resize(sz, 0); b.resize(sz, 0); vector c=NTTPart<998244353,3>::mul(a, b); c.resize(m); return c; } std::vector mul_ll(std::vector a, std::vector b) { size_t m = a.size() + b.size() - 1; sz = 1; while (m > sz) sz <<= 1; tmp.resize(sz); a.resize(sz, 0); b.resize(sz, 0); vector c=NTTPart<998244353,3>::mul(a, b); vector d=NTTPart<1224736769,3>::mul(a, b); c.resize(m);d.resize(m); vector e(m); rep(i,m)e[i]=ChineseRem({c[i],d[i]},{998244353,1224736769}).first; return e; } }; //Big ll vector carry_and_fix(vector digit) { ll N = digit.size(); for(ll i = 0; i < N - 1; ++i) { // 繰り上がり処理 (K は繰り上がりの回数) if(digit[i] >= 10) { ll K = digit[i] / 10; digit[i] -= K * 10; digit[i + 1] += K; } // 繰り下がり処理 (K は繰り下がりの回数) if(digit[i] < 0) { ll K = (-digit[i] - 1) / 10 + 1; digit[i] += K * 10; digit[i + 1] -= K; } } // 一番上の桁が 10 以上なら、桁数を増やすことを繰り返す while(digit.back() >= 10) { ll K = digit.back() / 10; digit.back() -= K * 10; digit.push_back(K); } // 1 桁の「0」以外なら、一番上の桁の 0 (リーディング・ゼロ) を消す while(digit.size() >= 2 && digit.back() == 0) { digit.pop_back(); } return digit; } vector string_to_bigll(string S) { ll N = S.size(); // N = (文字列 S の長さ) vector digit(N); for(ll i = 0; i < N; ++i) { digit[i] = S[N - i - 1] - '0'; // 10^i の位の数 } return digit; } string bigll_to_string(vector digit) { ll N = digit.size(); // N = (配列 digit の長さ) string str = ""; for(ll i = N - 1; i >= 0; --i) { str += digit[i] + '0'; } return str; } vector addition(vector digit_a, vector digit_b) { ll N = max(digit_a.size(), digit_b.size()); // a と b の大きい方 vector digit_ans(N); // 長さ N の配列 digit_ans を作る for(ll i = 0; i < N; ++i) { digit_ans[i] = (i < digit_a.size() ? digit_a[i] : 0) + (i < digit_b.size() ? digit_b[i] : 0); // digit_ans[i] を digit_a[i] + digit_b[i] にする (範囲外の場合は 0) } return carry_and_fix(digit_ans); // 2-4 節「繰り上がり計算」の関数です } vector subtraction(vector digit_a, vector digit_b) { ll N = max(digit_a.size(), digit_b.size()); // a と b の大きい方 vector digit_ans(N); // 長さ N の配列 digit_ans を作る for(ll i = 0; i < N; ++i) { digit_ans[i] = (i < digit_a.size() ? digit_a[i] : 0) - (i < digit_b.size() ? digit_b[i] : 0); // digit_ans[i] を digit_a[i] - digit_b[i] にする (範囲外の場合は 0) } return carry_and_fix(digit_ans); // 2-4 節「繰り上がり計算」の関数です } vector multiplication(vector digit_a, vector digit_b) { vector res=NTT::mul(digit_a,digit_b); return carry_and_fix(res); } bool compare(vector digit_a, vector digit_b, bool equal){//等しい時はequalが帰ってくる ll NA = digit_a.size(); // A の桁数 ll NB = digit_b.size(); // B の桁数 if(NA != NB)return NA < NB; for(ll i = NA - 1 ;i >= 0;i--){ if(digit_a[i] != digit_b[i])return digit_a[i] < digit_b[i]; } return equal; } ll mod=1000000007;//一次元ベクトルの高速化dp vector matmul(vector &dp, vector> &mt){ ll m=dp.size(); vector ret(m,{0}); rep(i,m)rep(j,m){ ret[i]=addition(ret[i],multiplication(mt[i][j],dp[j])); /*ret[i]+=mt[i][j]*dp[j]; ret[i]%=mod;*/ } return ret; } vector> update(vector> &mt){ ll m=mt.size(); vector> ret(m,vvl(m,{0})); rep(i,m)rep(j,m)rep(k,m){ ret[i][j]=addition(ret[i][j],multiplication(mt[i][k],mt[k][j])); /*ret[i][j]+=mt[i][k]*mt[k][j]; ret[i][j]%=mod;*/ } return ret; } void matpow(vvl &dp, vector &mt, ll k){ while(k){ if(k&1)dp=matmul(dp,mt); mt=update(mt); k/=2; } } int main(){ ll n;cin >> n; if(n==2){ cout << 4 << endl; cout << 1 << endl;return 0; } if(n%2){ vector> mat(2,vvl(2,{1})); mat[1][1][0]=0; vvl dp(2,{1});dp[1][0]=0; matpow(dp,mat,n-1); cout << n << endl; cout << bigll_to_string(dp[0]) << endl; } else{ vector> mat(2,vvl(2,{1})); mat[1][1][0]=0; auto tmp=mat; vvl dp(2,{1});dp[1][0]=0; matpow(dp,tmp,n/2-2); //cout << bigll_to_string(dp[0]) << endl; //cout << bigll_to_string(dp[1]) << endl; vvl ndp(2); ndp[0]=addition(addition(dp[0],dp[0]),dp[1]); ndp[1]=dp[0]; //cout << bigll_to_string(ndp[0]) << endl; //cout << bigll_to_string(ndp[1]) << endl; matpow(ndp,mat,n/2-2); cout << n << endl; cout << bigll_to_string(ndp[0]) << endl; //cout << bigll_to_string(ndp[1]) << endl; } }