Problem Link :
Practice
Contest
Author: Amrutansu Garanaik , Abhishek Patnaik
Tester: Keshow Sablaka, Amit Das
Editorialist: Amrutansu Garanaik , Amit Kumar Sahu
Difficulty :
cakewalk
Problem :
Given n numbers, multiply all the numbers modulo 10^9+7.
Explanation
The problem can be easily solved using modular arithmetic.
(a X b) % MOD = ((a % MOD) X (b % MOD)) % MOD
We need to use a result variable initialized to 1 and multiply each value one by one and on each
multiplication, find the result % MOD and store it in result.
result = result X number
result = result % MOD
One thing to remember is, the range of numbers is upto 10^16. So if the previous content of the
variable result is high (say 10^8) and we multiply it with 10^16, the result will be 10^24 causing
overflow and a Wrong answer verdict. So, initially, take the modulo of each number and then start
multiplying it. See setter solution for implementations.
asked
03 Apr '15, 20:33
3★dragonemperor
893●2●11●35
accept rate:
10%