Problems > Product Modulo 1e9+7 > Editorial

Product Modulo 1e9+7 — Solution & Editorial

Back to the Problem

Reduce every factor modulo M as you multiply. In languages where % can return negatives, normalize with ((x % M) + M) % M.

Complexity: O(N)

Watch out: In C++/Java the remainder of a negative number is negative — normalize before printing.