Modulo 1000000007(10^9+7)

Mod or modulo is referred to the symbol which is ‘shift’ key away from 5 on your keyboard (%). Locally we have used it as percentage symbol but you are here because you are from coding community so for us it is MODULO.

Basic task

The task of modulo operator is to give the remainder. It is a binary operator and with binary it means that two operands are needed to compute the operation.

Eg- say :: a=4,b=2 and perform a%b the result is zero. As 4 is multiple of 2 so remainder is zero.

Eg- say:: a=5,b=2 and perform a%b the result will be 1. As nearest multiple to 5 which is less than 5 is 4 so 1 is left and that’s remainder.

Eg- say:: a=9, b=11 and perform a%b the result will be 9. As 9<11 and 11 is the first positive multiple of 11.

Need of modulo?

Modulo is needed if at the end of programs then it is usually to prevent overflow. Otherwise if needed anywhere else then it is mostly for its operation purpose. Let’s get back to our overflow concept.

C/C++ has the largest primitive integer data structure of ‘long long int. It ranges from (-2^63) to (2^63 – 1). This range varies depending on whether it is signed or unsigned. If it is unsigned the range starts from 0 and goes till (2^63 – 1) . Only integers of maximum value (9×10^18) can be stored in this data type. But in some rather many this range of long long int becomes insufficient to store the growing value of answer. So to bring these answer to this limit you are asked to mod your ans with (10^9+7) to give the output.

Eg- One of the example for this is factorial of large numbers. Finding factorial is easy task but storing factorial is not that simple. you cannot store factorial value of large numbers, say 65! or 100!. These value are too large to store in a variable so you might be asked to mod it and this will change the answer but the program will be built in such as manner so that the modulo output will be accepted.

Way to Declare-

1)You can declare with a variable- unsigned int M = 1000000007; other 2)By declaring it as Macro. it will serve the same purpose.
3)Another way of declaring which involves ‘e’(1e9+7). you can declare it as variable or macro.

Thanks for visiting and reading this post. If you find it helpful or feel some room for improvement then please comment by your point or appreciation.

This article has been contributed by Thakurnik

Write a comment