Perfect and Simple Solution which passes, all kinds of inputs like aaaa output =1;


#1

int kmp(string s){
int n=s.size();
vector v(n,0);
int j=0;
for(int i=1;i<n;i++){
if(s[i]==s[j]){
v[i]=j+1;j++;
}
else{
while(j!=0){
j=v[j-1];
if(s[i]==s[j]){
v[i]=j+1;j++;break;
}
}if(j==0)v[i]=0;
}
} return v[n-1];
}
int Solution::solve(vector &A) {
int n1=A.size();
vector t(n1);
for(int i=0;i<n1;i++){
int len=kmp(A[i]); //maximum prefix which is also suffix length
int n=A[i].size();
if(n%(n-len)==0)
n=n-len; //repeating substring of length n-len
long long int time=1,val=1;
while(val%n!=0){
time++; //1,2,3 time
val+=time; //1+2+3 n*(n+1)/2;
}
t[i]=time;
}
long long ans=1; int m=1000000007;
for(int i=0;i<n1;i++){
for(int j=i+1;j<n1;j++){
t[j]=t[j]/__gcd(t[i],t[j]);
}
ans=(ans*t[i])%m;
ans=(ans+m)%m;
} return ans;
}
Hope this helps