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

×

BIGO05-Editorial

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.

This question is marked "community wiki".

asked 03 Apr '15, 20:33

dragonemperor's gravatar image

3★dragonemperor
89321135
accept rate: 10%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×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