Answer mod 10e9+7 is misleading in this question

My issue

The question says the answer should be modulo 10e9+7 but all excepted answer put answer = answer modulo 10e9+7 for each updation in value of amswer. Isn’t it misleading

My code

   for i in lst:
       answer = answer * i 
   print(answer % (10**9 + 7))

Accepted code

   for i in lst:
       answer = (answer * i ) % (10 ** 9 + 7)
   print(answer)

Problem Link: Encrypt Value Practice Coding Problem - CodeChef

Not all that. Actually that was the difficulty of this problem.

For C/C++ users, this isn’t a issue. They MUST use the module inside, otherwise, the number would overflow.

However, in Python, even though you can store big numbers, those are insidely stored in arrays and data structures you can’t see. The bigger the number, the more difficult is for the computer to use it.

Module is not necessary a O(1) operation -depends on the processor-, let alone in Python interpreter with super big numbers in large data structures storing all the number you may think is unique.

Hence, module in large number is one of the most costly computational operations in Python. It’s very better to avoid creating a super big thing number and then pretending manipulating it.
That Python allows you to do some things doesn’t mean you should do so.

When you see a module to a huge number in Python, you might fear a little.

1 Like