#include<bits/stdc++.h>
using namespace std;
#define rev(n) (quick_mod(n,mod-2))
#define del(n) ((n%mod+mod)%mod)
typedef long long ll;
const int maxn=1e5+5;
const ll mod=1e9+9;
int t[maxn];
char s[maxn];
ll quick_mod(ll n,ll m)
{
ll res=1;
while(m)
{
if(m&1)
res=(res*n)%mod;
n=n*n%mod;
m/=2;
}
return res;
}
int main()
{
ll ans,n,a,b,tp,arev,brev,tpp,k;
while(scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&k)!=EOF)
{
ans=0;
scanf("%s",s);
for(int i=0;i<k;i++)
t[i]=(s[i]=='+'?1:-1);
if(quick_mod(b,k)*rev(quick_mod(a,k))==1)
tp=quick_mod(a,n)*((n+1)/k)%mod;
else
tp=del(quick_mod(a,n+1)-quick_mod(b,n+1))*quick_mod(a,k-1)%mod*rev(del(quick_mod(a,k)-quick_mod(b,k)))%mod;
arev=quick_mod(a,(ll)mod-2);
for(int i=0;i<k;i++)
{
ans=((ans+t[i]*tp)%mod+mod)%mod;
tp=tp*arev%mod*b%mod;
}
printf("%I64d\n",ans);
}
return 0;
}
codeforces 963A Alternating Sum 数学
最新推荐文章于 2021-11-11 10:23:15 发布