➤ Problem Link : 1349A. Orac and LCM
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int n;
cin>>n;
ll arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
ll ans=-1;
ll curr=arr[n-1];
ll it;
for(int i=n-2;i>=0;i--)
{
int gd=__gcd(curr,arr[i]);
it=curr*(arr[i]/gd);
if(ans==-1)
ans=it;
else
ans=__gcd(ans,it);
curr=__gcd(curr,arr[i]);
}
cout<<ans;
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
