You are given an array arr[] of numbers of size N. You need to multiply these numbers and find the remainder when the product of these numbers is divided by a number K.
 
Example 1:
Input:
N = 3
arr[] = {4, 6, 7}
K = 3
Output:
0
Explanation:
4*6*7 = 168%3 = 0
Example 2:
Input:
N = 2
arr[] = {1, 6}
K = 5
Output:
1
Explanation:
1*6 = 6%5 = 1
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function remArray() which takes a integers N, an array arr[] of size N and another integer K as input and returns the Product of the array modulo K.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N,K,arr[i] <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3



class Solution:

    def remArray(self, N, arr, K):

        # code here

Solutions:
class Solution:

	def remArray(self, N, arr, K):
		pro = 1
		while N > 0:
			pro = pro * arr[N - 1] % K
			N -= 1
		return pro % K


class Solution:

	def remArray(self, N, arr, K):
		mul = 1
		for i in arr:
			mul = mul * i % K
		mul = mul % K
		return mul


class Solution:

	def remArray(self, N, arr, K):
		output = 1
		for item in arr:
			output = output * item % K
		return output


class Solution:

	def remArray(self, N, arr, K):
		res = 1
		for i in range(N):
			res = res * (arr[i] % K) % K
		return res % K


from functools import reduce

class Solution:

	def remArray(self, N, arr, K):
		mul = 1
		for i in range(N):
			mul = mul * (arr[i] % K) % K
		return mul % K


class Solution:

	def remArray(self, N, arr, K):
		p = 1
		for i in range(len(arr)):
			p = p * arr[i] % K
		return p


class Solution:

	def remArray(self, N, arr, K):
		prod = 1
		for i in range(0, N):
			prod = prod * (arr[i] % K) % K
		return prod % K


class Solution:

	def remArray(self, N, arr, K):
		Mul = 1
		M = 10 ** 9 + 7
		for i in arr:
			Mul = Mul * i % K
		return Mul % K


class Solution:

	def remArray(self, N, arr, K):
		p = 1
		for i in arr:
			p = p * i % K
		return p % K
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = list(map(int, input().split()))
		K = int(input())
		ob = Solution()
		print(ob.remArray(N, arr, K))


class Solution:

	def remArray(self, N, arr, K):
		m = 1
		for j in arr:
			m = m * j % K
		return m


import random

class Solution:

	def remArray(self, N, arr, K):
		result = 1
		for i in range(0, N):
			result = result * arr[i] % K
		return result % K