Watson gives Sherlock an array of elements and two arrays and , of elements each. Then he asks Sherlock to perform the following program:
for i = 1 to M do
for j = 1 to N do
if j % B[i] == 0 then
A[j] = A[j] * C[i]
This code needs to be optimized. Can you help Sherlock and tell him the resulting array ? You should print all the array elements modulo .
The first line contains two integer, and . The next line contains integers, the elements of array . The last two lines contain integers each, the elements of array and , respectively.
Print space-separated integers, the elements of array after performing the program modulo .
1 2 3 4
1 2 3
13 29 71
13 754 2769 1508