109 is -7 modulo 1000000007.
Break the 100 digit number N
into blocks of 9 digits (a0, a1, ...) starting from the right. We have:
N = a0 + a1*10^9 + a2*10^18 + ...
The modulus is a0 - 7*a1 + 49*a2 - ...
For example, suppose you are to calculate 87564875326485487234854862386245865486238654862 modulo 1000000007. You break this string of digits into blocks of 9 starting from the right:
- a0 = 238654862
- a1 = 245865486
- a2 = 245865486
- a3 = 854862386
- a4 = 485487234
- a5 = 564875326
- a6 = 87
Now you convert each block into an integer and calculate m = a0 - 7*a1 + 49*a2 - 323*a3 +... (hint: use 64 bit integers).
Now N = m (mod 1000000007)
.