提交时间:2024-01-04 13:14:06
运行 ID: 119129
#include<bits/stdc++.h> using namespace std; #define fo(v,a,b)for(int v=a;v<=b;v++) #define fr(v,a,b)for(int v=a;v>=b;v--) #define il inline typedef long long ll; const ll P=1e9+7; const int N=1000010; int n; char s[N],Next[N],dep[N]; ll ans; int get(int x,int lim) { return 2*x<=lim?x:Next[x]=get(Next[x],lim); } void solve() { scanf("%s",s+1); n=strlen(s+1); int j=0; Next[1]=0,dep[1]=1; fo(i,2,n){ while(j>0&&s[j+1]!=s[i]) j=Next[j]; if(s[j+1]==s[i])j++; Next[i]=j,dep[i]=dep[Next[i]]+1; } fr(i,n,2)get(i,i); ans=1; fo(i,1,n)ans=ans*(dep[Next[i]]+1)%P; printf("%lld\n",ans); } int main() { int T; cin>>T; while(T--) solve(); return 0; }