# Archery | Hackerearth solution

Problem

N archers are shooting arrows at targets. There are infinite targets numbered starting with 1. The ${�}^{�\mathrm{â„Ž}}$ archer shoots at all targets that are multiples of ${�}_{�}$.

Find the smallest target that is hit by all the archers.

### Input

The first line contains an integer T - the total no. of testc ases.

T test cases follow. Each test case is of the following format:

The first line contains a natural number - N - the number of archers. The second line contains N space-separated integers, where the ${�}^{�\mathrm{â„Ž}}$ integer denotes the value of ${�}_{�}$ for the ${�}^{�\mathrm{â„Ž}}$ archer.

### Output

For each test case, print the smallest target that is hit by all archers on a new line.

### Constraints

$1\le �\le 5$

$1\le �\le 15$

$1\le {�}_{�}\le 48$

Sample Input
1
3
2 3 4

Sample Output
12

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The first archer shoots at targets 2, 4, 6, 8, 10, 12, 14, ...

The second archer shoots at targets 3, 6, 9, 12, ...

The third archer shoots at targets 4, 8, 12, 16, 20, ...

The smallest target at which all archers shoot is $12$.

Code(C++):-

#include <iostream>
using namespace std;
int main() {
cin.tie(NULL);
long long i, t, n, res, resc, r;
cin>>t;
for(int k=1; k<=t; k++)
{
cin>>n;
int v[n+1];
for(i=1; i<=n; i++)
cin>>v[i];
res=1;

for(i=1; i<=n; i++)
{
resc=res;
res*=v[i];

r=resc%v[i];
while(r)
{
resc=v[i];
v[i]=r;
r=resc%v[i];
}
res/=v[i];
}
cout<<res<<"\n";
}
return 0;
}

### Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-