/* -*- coding: utf-8 -*- * * 978.cc: No.978 Fibonacci Convolution Easy - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 2000000; const int MOD = 1000000007; const int A0 = 0, A1 = 1; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], ass[MAX_N]; /* subroutines */ /* main */ int main() { int n, p; scanf("%d%d", &n, &p); as[0] = A0, as[1] = A1; for (int i = 2; i < n; i++) as[i] = ((ll)p * as[i - 1] % MOD + as[i - 2]) % MOD; ass[0] = as[0]; for (int i = 1; i < n; i++) ass[i] = (ass[i - 1] + as[i]) % MOD; int sum = 0; for (int i = 0; i < n; i++) sum = (sum + (ll)as[i] * ass[i] % MOD) % MOD; printf("%d\n", sum); return 0; }