The Modular Trick

Problem – Chef And Number Game

The question asks the programmer to print the summation of factorials between a given range of numbers modular 10e9+7. The trick is to add 10e9+7 in the final expression (line 43) and then taking the modulo of the whole.

Update- The one thing that skipped was that in line 38, we might score a negative value. Which in turn suggests that we have to take modulo of a negative number which obviously won’t return the answer that we quite expect. So as to overcome that problem I added the “mod” macro back into the result so that it can return modulo of a positive value without affecting the answer.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s