×

BIGO05-Editorial

Author: Amrutansu Garanaik , Abhishek Patnaik
Tester: Keshow Sablaka, Amit Das
Editorialist: Amrutansu Garanaik , Amit Kumar Sahu

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.

This question is marked "community wiki".

89321135
accept rate: 10%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,683
×1,652
×15
×1

question asked: 03 Apr '15, 20:33

question was seen: 514 times

last updated: 03 Apr '15, 20:33