#P1493D. GCD of an Array
GCD of an Array
Description
You are given an array of length . You are asked to process queries of the following format: given integers and , multiply by .
After processing each query you need to output the greatest common divisor (GCD) of all elements of the array .
Since the answer can be too large, you are asked to output it modulo .
The first line contains two integers — and ().
The second line contains integers () — the elements of the array before the changes.
The next lines contain queries in the following format: each line contains two integers and (, ).
Print lines: after processing each query output the GCD of all elements modulo on a separate line.
Input
The first line contains two integers — and ().
The second line contains integers () — the elements of the array before the changes.
The next lines contain queries in the following format: each line contains two integers and (, ).
Output
Print lines: after processing each query output the GCD of all elements modulo on a separate line.
Note
After the first query the array is , .
After the second query — , .
After the third query — , .
Here the function denotes the greatest common divisor.