Alexy and microcontroller frezee

Description:

Alexey is trying to develop a program for a very simple microcontroller. It makes readings from various sensors over time, and these readings must happen at specific regular times. Unfortunately, if two of these readings occur at the same time, the microcontroller freezes and must be reset. There are N different sensors that read data on a regular basis. For each i from 1 to N, the reading from sensor i will occur every Ai milliseconds with the first reading occurring exactly Ai milliseconds after the microcontroller is powered up. Each reading takes precisely one millisecond on Alexey's microcontroller. Alexey wants to know when the microcontroller will freeze after he turns it on. Test Case 1 Input (stdin) 3 3 2 3 5 4 1 8 7 11 4 4 4 5 6 Expected Output 6 7 4 Test Case 2 Input (stdin) 3 3 2 3 6 4 1 8 17 11 4 4 4 5 6 Expected Output 6 8 4

Program :

#include <bits/stdc++.h>

#define ll long long

using namespace std;

 

int gcd(int a,int b){

while(a!=b){

if(a==1 || b==1) return 1;

if(a==0) return b;

if(b==0) return a;

(a>b)?(a=a%b):(b=b%a);

}

return a;

}

 

long long lcm(int a,int b){

return (a/(gcd(a,b)))*(long long)b;

}

int main(){

int t;

cin>>t;

while(t--){

int n;

cin>>n;

int a[n];

long long min=pow(10,18);

for(int i=0;i<n;i++) cin>>a[i];

for(int i=0;i<n;i++){

for(int j=i+1;j<n;j++){

if(a[j]>=min) continue;

long long x=lcm(a[i],a[j]);

if(x<min) min=x;

}

}

cout<<min<<endl;

}

return 0;

}