Problem:
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
The first line contains a single integer N
N denoting the size of the array. The next line contains N
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.
Print a single integer denoting the product of all the elements of the array Modulo 109+7.
Constraints:
1≤N≤103
1≤N≤103
1≤A[i]≤103
SAMPLE INPUT
5 1 2 3 4 5
SAMPLE OUTPUT
120
Code:
import java.lang.Math; import java.util.Scanner; class TestClass { public static void main(String args[] ) throws Exception { Scanner sc=new Scanner(System.in); int []A=new int[1000]; int a=sc.nextInt(); int i; double answer=1.0; for(i=0;i<a;i++) { A[i]=sc.nextInt(); } for(i=0;i<a;i++) { answer=(A[i]*answer)%((Math.pow(10,9))+7); } System.out.println((int)answer); } }
Comments
Post a Comment