Watsy & his mam editorial

Prerequisite:

Modulo operation and its properties

Difficulty:

Easy

Explanation:

We need to multiply the given n numbers and as it can be too large we need to print the value of answer
modulo 1000000009 (10^9+7)

The distributive law i.e. ab mod n = [(a mod n) (b mod n)] mod n will be implemented here. We first find n%1000000009 and then multiply with the answer and again we find ans%1000000009 and store in answer so that there is no overflow of datatype.

Solution:

#include
#define MOD 1000000007
int main()
{
	int test,n;
	unsigned long long ans,input;
	scanf("%d",&test);
	while(test--)
	{
		scanf("%d",&n);
		ans = 1;
		while(n--)
		{
			scanf("%llu",&input);
			input %= MOD;
			ans *= input;
			ans %= MOD;
		}
		printf("%llu\n",ans);
	}
}
//