Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define maxn 1000010
- #define ll long long
- const int mod=1e9+7;
- const int c=26;
- const int p=101;
- const int Mod=1e9+7;
- int n,k;
- char s[maxn];
- ll pw(ll a,int n)
- {
- ll res=1;
- while(n)
- {
- if(n&1)res=res*a%mod;
- a=a*a%mod,n>>=1;
- }
- return res;
- }
- ll INV(ll a){return pw(a,mod-2);}
- int main()
- {
- scanf("%d%d",&n,&k);
- scanf("%s",s);
- ll pre=0,suf=0;
- ll ans=0;
- ll pp=1;
- for(int i=0;i<n;i++)
- {
- pre=(pre*p+(s[i]-'a'))%Mod,suf=(suf+pp*(s[n-i-1]-'a'))%Mod;
- pp=pp*p%Mod;
- if(pre==suf && 2*n-(i+1)<=k)ans++;
- }
- if(k>=2*n)
- {
- /*
- int m=k-2*n;
- ll tmp=pw(c,m+1);
- tmp=(tmp-1+mod)%mod;
- tmp=tmp*INV(c-1)%mod;
- ans=(ans+tmp)%mod;
- */
- int m=k-2*n;
- ll cur=1;
- for(int i=0;i<=m;i++)
- {
- ans=(ans+cur)%mod;
- cur=cur*c%mod;
- }
- }
- printf("%lld\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement