Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Watsy & his mam editorial

$
0
0

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<stdio.h>
#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);
    }
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>