Can anyone explain to me why I am getting Run Time error in this submission?

Looks like you are dividing by 0 in few of the lines of your code

1 Like

#include

using namespace std;

long long int gcd(long long int a,long long int b)

{

if (b == 0)

{

return a;

}

return gcd(b, a % b);

}

long long int lcm(long long int a[],long long int n)

{

long long int ans = a[0];

```
for (long long int i = 1; i < n; i++)
{
ans = (a[i] * ans)/ (gcd(a[i], ans));
}
return ans;
```

}

int main() {

// your code goes here

int t;

cin>>t;

while(t–)

{

long long int n,m;

cin>>n>>m;

```
long long int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
long long int ans=lcm(a,n);
long long int max=ans;
long long int num=1;
for(long long int i=2;i<=m;i++)
{
long long int cur=(i*ans)/(gcd(i,ans));
if(cur>max)
{
max=cur;
num=i;
}
}
cout<<num<<endl;
}
return 0;
```

}

what is the error in this i am geting wa

have a look here

please see this before solving MXMLCM