Getting WA in MXMLCM

What is wrong with this code?? PLease help!!

// C++ program to find LCM of n elements
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll findlcm(int arr[], int n)
{
ll ans = arr[0];
for (int i = 1; i < n; i++)
ans = (((arr[i] * ans)) /
(gcd(arr[i], ans)));

return ans;

}
int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int a[100000];
for(int i=0;i<n;i++)
cin>>a[i];
long long int d=findlcm(a, n);int flag=0,ctr;
for(int i=m;i>=1;i–)
{
if(d%i!=0)
{
if(flag<(di))
{
flag=d
i;
ctr=i;
}else if(flag==(d*i))
{
if(i<ctr)
ctr=i;
}
}
}
if(flag==0)
cout<<1<<endl;
else
cout<<ctr<<endl;
}
return 0;
}

I can just tell you that this happening because lcm is overflowing due to prime numbers which actually are pushing it out side the limit of long long. You can try like prime factors for every single no A1, A2,…,An and then find a number in 1 to M such that it can add more of the prime no and then try to maximize how ever I don’t know if this is going to work because i haven’t tried yet

https://www.codechef.com/viewsolution/30859741

What is wrong with this code?? PLease help!!