#include #include #include #include #include #include #include using namespace std; #define reE(i,a,b) for(auto (i)=(a);(i)<=(b);(i)++) #define rE(i,b) reE(i,0,b) #define reT(i,a,b) for(auto (i)=(a);(i)<(b);(i)++) #define rT(i,b) reT(i,0,b) #define rep(i,a,b) reE(i,a,b); #define rev(i,a,b) for(auto (i)=(b)-1;(i)>=(a);(i)--) #define itr(i,b) for(auto (i)=(b).begin();(i)!=(b).end();++(i)) #define LL long long #define all(b) (b).begin(),(b).end() #define LL long long #define MAX_LOGN 60 template struct Mr{ vector first; vector C; vector> bin; list usefulL; list usefulR; T zero, one; int M; //n(1,,,2M)をn(1,,,M)に修正、O(M^2) void form(vector &n){ rev(i, M + 1, 2 * M + 1) if(n[i].val){ reE(j, 1, M)n[i - j] = (n[i - j] + (C[M - j] * n[i])); n[i] = zero; } } //lとrを足し合わせる、O(M^2) inline void add(vector &l, vector &r, vector &ans){ usefulL.clear(); usefulR.clear(); reE(i,1,M){ if(l[i].val)usefulL.push_back(i); if(r[i].val)usefulR.push_back(i); } reE(i, 1, 2 * M)ans[i] = zero; for(auto &i:usefulL)for(auto &j:usefulR)ans[i + j] = (ans[i + j] + (l[i] * r[j])); form(ans); } //初期化、O(M*MAX_LOGN) Mr(const vector& f, const vector& c, int m, T e1, T e0){ M = m; first.reserve(M + 1); C.reserve(M); zero = e0, one = e1; first.push_back(zero); rT(i, M){ first.push_back(f[i]); C.push_back(c[i]); } bin.resize(MAX_LOGN); rT(i, MAX_LOGN)bin[i].resize(2 * M + 1); rE(i, 2 * M)bin[0][i] = zero; bin[0][1] = one; reT(i, 1, MAX_LOGN){ add(bin[i - 1], bin[i - 1], bin[i]); } } //N項目の計算、戻り値がTの形であることに注意、O(M^2*logN) vector calc(LL n){ n--; vector tmp, result = bin[0]; for (int b = 0; n; b++, n >>= 1) if (1 & n){ tmp = result; add(tmp, bin[b], result); } //reE(i, 1, M)ans = ans + (result[i] * first[i]); return result; } }; //テンプレート、デフォルトコンストラクタのオーバーロードを忘れない #define MOD 1000000007 struct X{ LL val; X(LL v){ val = v; } X(){ val = 0; } LL operator=(const X &another){ return val = another.val; } LL operator*(const X &another)const{ return (val*another.val) % MOD; } LL operator+(const X &another)const{ return (val + another.val) % MOD; } }; LL comb[1301]; LL temp2[51][1301][6] = { { {1} } }; LL temp1[51][1301][6]; LL dp[2601] = { 1 }; LL sumc[1301] = { 0 }; int sosuu[] = { 2, 3, 5, 7, 11, 13 }, gousei[] = { 4, 6, 8, 9, 10, 12 }; int p, c; vector A(1300), C(1300); int main(void){ LL N; cin >> N >> p >> c; //combの計算 for(int n=0;n= 0; i--){ sumc[i] = (sumc[i + 1] + comb[i]) % MOD; } LL res = 0; if (N < 1400){ for (LL i = 0; i < min(N,1300ll); i++) res = (res + dp[i] * sumc[min(N,1300ll) - i])%MOD; } else{ Mr mr(C, C, 1300, X(1), X(0)); auto cc = mr.calc(N + 1 - 1300); for (LL i = 0; i < 1300; i++) if(sumc[1300-i]){ LL x = 0; for (int j = 0; j < 1300; j++) x = (x + dp[i + j] * cc[j + 1].val) % MOD; res = (res + x*sumc[1300 - i])%MOD; } } cout << res << endl; return(0); }