#K85187. Next Simultaneous Watering Day
Next Simultaneous Watering Day
Next Simultaneous Watering Day
Problem Statement:
Given several plants with individual watering frequencies, determine the next day when all the plants will be watered simultaneously. The solution is to compute the least common multiple (LCM) of their watering frequencies modulo .
Recall that the LCM of two numbers (a) and (b) can be computed using the greatest common divisor (GCD) as follows:
[
\text{LCM}(a,b)=\frac{|a\times b|}{\gcd(a,b)}
]
For each test case, you will be given the number of plants followed by a list of watering frequencies. Your task is to compute the next simultaneous watering day for each test case.
inputFormat
Standard Input:
The first line contains an integer (T) ((1\leq T\leq 10)), the number of test cases. Each test case consists of two lines:
1. The first line contains an integer (N) ((1\leq N\leq 10^5)), the number of plants.
2. The second line contains (N) space-separated integers representing the watering frequencies in days.
It is guaranteed that the sum of (N) over all test cases does not exceed (10^5).
outputFormat
Standard Output:
For each test case, output a single line containing the next simultaneous watering day (i.e., the LCM of the frequencies modulo (10^9+7)).## sample
2
3
2 3 5
2
4 6
30
12
</p>