The function to calculate time is working fine individually but collective lcm is giving wrong result what is wrong? plsease help


#1

int T(string s)
{
int n=s.size();
string temp=s;
int t=1;
string newstr="";
while(newstr!=s)
{
newstr=temp.substr(t%n)+temp.substr(0,t%n);
if(newstr==s)
{
break;
}
temp=newstr;
newstr="";
t++;
}
return t;
}
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}

long long int lcm(vectort)
{
int n=t.size();
long long int ans=t[0];
for(int i=1;i<n;i++)
{
ans = (((t[i] * ans)) /(gcd(t[i], ans)));
return ans;
}
}

int Solution::solve(vector &a) {
if(a.size()==0)
return 1;
vectort;
for(int i=0;i<a.size();i++)
{
t.push_back(T(a[i]));
}
return lcm(t);

}


#2

As numbers are quite large, take out lcm by finding factors of each nos…and also note to use a^b%m function except pow in that