/* -*- coding: utf-8 -*- * * 3457.cc: No.3457 Fibo-shrink - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_K = 500 + 1; const int MOD = 10007; /* typedef */ template struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } 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 { return MI(MOD - 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); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; using mi = MI; using vec = mi[MAX_K]; using mat = vec[MAX_K]; /* global variables */ mi fs[MAX_K], invfs[MAX_K]; mat ma, mb; vec va, vb; /* subroutines */ inline void initvec(const int n, vec a) { fill(a, a + n, 0); } inline void initmat(const int n, mat a) { for (int i = 0; i < n; i++) initvec(n, a[i]); } inline void unitmat(const int n, mat a) { initmat(n, a); for (int i = 0; i < n; i++) a[i][i] = 1; } inline void copymat(const int n, const mat a, mat b) { for (int i = 0; i < n; i++) copy(a[i], a[i] + n, b[i]); } inline void addmat(const int n, const mat a, const mat b, mat c) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i][j] = a[i][j] + b[i][j]; } inline void mulmat(const int n, const mat a, const mat b, mat c) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { c[i][j] = 0; for (int k = 0; k < n; k++) c[i][j] += a[i][k] * b[k][j]; } } inline void powmat(const int n, const mat a, int b, mat c) { mat s, t; copymat(n, a, s); unitmat(n, c); while (b > 0) { if (b & 1) { mulmat(n, c, s, t); copymat(n, t, c); } mulmat(n, s, s, t); copymat(n, t, s); b >>= 1; } } inline void mulmatvec(const int n, const mat a, const vec b, vec c) { for (int i = 0; i < n; i++) { c[i] = 0; for (int j = 0; j < n; j++) c[i] += a[i][j] * b[j]; } } void printmat(const int n, const mat a) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j) putchar(' '); printf("%d", a[i][j]); } putchar('\n'); } } /* main */ int main() { int k, s, n; scanf("%d%d%d", &k, &s, &n); k++; fs[0] = fs[1] = 1; for (int i = 2; i < k; i++) fs[i] = fs[i - 2] + fs[i - 1]; for (int i = 0; i < k; i++) invfs[i] = fs[i].inv(); initmat(k, ma); for (int i = 0; i < k - 1; i++) ma[i][i + 1] = 1; for (int j = 0; j < k; j++) ma[k - 1][j] = invfs[k - 1 - j]; powmat(k, ma, n - 1, mb); initvec(k, va); va[k - 1] = s; mulmatvec(k, mb, va, vb); printf("%d\n", (int)vb[k - 1]); //for (int i = 0; i < k; i++) printf(" %d", (int)vb[i]); putchar('\n'); return 0; }