The summation of proportional series must be discussed in categories! ! ! ! ! ! ! ! ! ! ! !
1 #include<bits/stdc++.h> 2 #define LL long long 3 #define fi first 4 #define se second 5 #define mk make_pair 6 #define pii pair<int,int> 7 #define ull unsigned long long 8 using namespace std; 9 10 const int N=1e6+7; 11 const int M=100+7; 12 const int inf=0x3f3f3f3f; 13 const LL INF=0x3f3f3f3f3f3f3f3f; 14 const int mod=1e9 + 9; 15 16 LL n, a, b, k; 17 char s[N]; 18 19 LL q_pow(LL a, LL b) { 20 LL ans = 1; 21 while(b) { 22 if(b & 1) ans = ans * a % mod; 23 a = a * a % mod; b >>= 1; 24 } 25 return ans; 26 } 27 28 LL ivn(LL x) { 29 return q_pow(x, mod - 2); 30 } 31 32 33 int main() { 34 35 scanf("%lld%lld%lld%lld", &n, &a, &b, &k); 36 scanf("%s", s); 37 LL w = q_pow(b, k) * ivn(q_pow(a, k)) % mod; 38 w = (w + mod) % mod; 39 40 LL ans = 0; 41 LL cnt = (n + 1) / k; 42 43 for (LL i = 0 ; i <k; i ++ ) { 44 LL ret1 = q_pow (a, n - i) * q_pow (b, i)% mod; 45 LL ret2 = ( 1 - q_pow (w, cnt) + mod)% mod; 46 LL ret3 = ivn (( 1 - w + mod)% mod); 47 LL ret = (((ret1 * ret2)% mod) * ret3)% mod; 48 if (w == 1 ) ret = (ret1 * cnt)% mod; 49 if (s [i] == ' - ' ) ret = - ret; 50 ans = (ans + ret + mod)% mod; 51 } 52 printf("%lld\n", ans); 53 return 0; 54 } 55 /* 56 */