You are not logged in. Please login at to post your questions!



Problem Link :


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

Difficulty :


Problem :

Given n numbers, multiply all the numbers modulo 10^9+7.


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".

asked 03 Apr '15, 20:33

dragonemperor's gravatar image

accept rate: 10%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 03 Apr '15, 20:33

question was seen: 514 times

last updated: 03 Apr '15, 20:33