1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <bits/stdc++.h> #define Go(i , x , y) for(register int i = x; i <= y; i++) #define God(i , y , x) for(register int i = y; i >= x; i--) typedef long long LL; template < typename T > void sc(T& t) { char c = getchar(); T x = 1; t = 0; while(!isdigit(c)) {if(c == '-') x = -1; c = getchar();} while(isdigit(c)) t = t * 10 + c - '0' , c = getchar();t *= x; } template < typename T , typename... Args > void sc(T& t , Args&... args) {sc(t); sc(args...);}
const int N = 1000000 + 5; char a[N]; int t , next[N] , cnt[N] , ans[N]; int main() { sc(t); while(t--) { memset(next , 0 , sizeof(next)); memset(cnt , 0 , sizeof(cnt)); memset(ans , 0 , sizeof(ans)); scanf("%s" , (a+1)); int n = strlen(a+1); LL mult = 1; next[1] = 0 , ans[1] = 1; Go(i , 2 , n) { int j = next[i-1]; while(j && a[j+1] != a[i]) j = next[j]; if(a[j+1] == a[i]) next[i] = j+1 , j++; else next[i] = 0; ans[i] = ans[j] + 1; }
for(int i=2 , j=0; i <= n; i++) { while(j && a[j+1] != a[i]) j = next[j]; if(a[j+1] == a[i]) ++j; while((j << 1) > i) j = next[j]; mult = mult * (ans[j] + 1) % (LL)(1e9 + 7); } printf("%lld\n" , mult); } return 0; }
|