Header Ads Widget

Archery | Hackerearth solution

 Problem

N archers are shooting arrows at targets. There are infinite targets numbered starting with 1. The  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  integer denotes the value of  for the  archer.

Output

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

Constraints

15

115

148

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:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments