Why 10^9 + 7?
This summaries the reason why this modular exist.
Last updated
This summaries the reason why this modular exist.
Last updated
In most of the coding question, we would saw this specific magic number:
And they want us to modular this value. Once I wondered, why this value.
After been some research, there are few reasons why this particular number for that.
It is the first 10-digit prime number.
The number is large enough to verify the answer is correct, but not too large that causing some of the programming language can't output such large number or omit out some digits to gives wrong answer.
Prevent integer overflow.
If problem constraints are large integers, only efficient algorithms can solve them in an allowed limited time.
Any prime number less than will be fine in order to prevent possible overflows. If the output number is exponentially long that may hit , the question will obligately request you to mod the answer into this magic number.