LCM^k

3.7

69 votes
, Basic Math, Algorithms, Math
Problem

Given three integers N,M,K and array of integers a1,a2,...,an.
Find the value of LCM(a1k,a2k,...,ank) mod M, where LCM means Least Common Multiple.

Input

The first line of the input contains a single integer T denoting the number of test cases(1 ≤ T ≤ 10). 
The description of T test cases follows.
First line contains three positive integers N, M, K(1 ≤ N ≤ 3 * 105, 1 ≤ M, K ≤ 109).
The second line contains N space-separated integers a1,a2,...,an.(1 ≤ ai ≤ 106,1 ≤ iN).

Output
For each test case print the value of LCM(a1k,a2k,...,ank) mod M.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the test LCM(173,23,93,43,123) = 229220928, 229220928 mod 20 = 8.

Editor Image

?