Skip to content

Instantly share code, notes, and snippets.

@sai-sondarkar
Last active September 3, 2020 08:43
Show Gist options
  • Save sai-sondarkar/c37586291373aaa58e016891eccf81eb to your computer and use it in GitHub Desktop.
Save sai-sondarkar/c37586291373aaa58e016891eccf81eb to your computer and use it in GitHub Desktop.
You have been given an array A of size N consisting of positive integers. You need to find and print the product of all the number in this array Modulo 109+7.
Input Format:
The first line contains a single integer N denoting the size of the array. The next line contains N space separated integers denoting the elements of the array
Output Format:
Print a single integer denoting the product of all the elements of the array Modulo 109+7.
Constraints:
1≤N≤103
1≤A[i]≤103
SAMPLE INPUT
5
1 2 3 4 5
SAMPLE OUTPUT
120
Explanation
There are 5 integers to multiply. Let's store the final answer in answer variable. Since 1 is identity value for multiplication, initialize answer as 1.
So the process goes as follows:
answer=1
answer=(answer×1) % (109+7)
answer=(answer×2) % (109+7)
answer=(answer×3) % (109+7)
answer=(answer×4) % (109+7)
answer=(answer×5) % (109+7)
The above process will yield answer as
@Privatedogg
Copy link

Privatedogg commented Jun 12, 2020

i think their required some changes in question
instead of (109+7) it should be Modulo (10^9+7) value of (1000000007)
than only we can get the required ans we want

@Ankit1598
Copy link

Ankit1598 commented Jun 12, 2020

i think their required some changes in question
instead of (109+7) it should be Modulo (10^9+7) value of (1000000007)
than only we can get the required ans we want

I think so too

Also in constraints part it needs to be (10^3)

@Aakash-Pacherkar
Copy link

Aakash-Pacherkar commented Jun 12, 2020

There is a printing mistake in the program.
To avoid overflow it should be (10^9+7) instead of (109+7).

@Aakash-Pacherkar
Copy link

There is a printing mistake in the question !!
To avoid overflow it should be (10^9+7) and not (109+7)

@Manoj1723
Copy link

I think it should be (109**7) not (109+7)

@milan-vishnoi
Copy link

@sai-sondarkar sir, please clear the doubt whether it is (10^9)+7 or (109^7) or (109+7) ?

@prathameshp107
Copy link

@sai_sondarkar question looks it will be 10^9 instead of 109 can you explain it is right or changes

@RoHaN0512
Copy link

RoHaN0512 commented Jun 17, 2020

can the integers be random or do they have to be 1,2,3...and so on?
what will the final answer for the above give example?

@subalakshmij
Copy link

n=int(input("Size of array: "))
l=list(map(int,input("enter array element with space: ").split()))
product=1
for i in l:
product*=i
result=product%((10**9)+7)
print(result)

@padhu020391
Copy link

arr = int(input("Enter Array Size: "))
lst = list(map(int,input("Enter Array Element With Space: ").split()))
product = 1
for i in lst:
product = product*i
result = product%((10**9)+7)
print(result)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment