Discussion (xia che ≖‿≖✧) magic number - 1000000007

            Why should 1,000,000,007 modulo (remainder)

  Look at this blog and I basically have the same brain into the pit, or that I read an article factorial of large numbers, large numbers of permutations and combinations and the like blog been fooled over. I just said those types of topics generally require the output of 1,000,000,007 modulo (remainder)

Why is it always 1,000,000,007 = _ =?

  I guess this is because ah this for several reasons:

  1. 1000000007 is a number (prime) quality, the number of confrontation can take more than the maximum to avoid conflict ( "Discrete Mathematics' Number Theory section)
  2. int32 bit maximum of 2 31 -1 = 2147483647, 1000000007 so for int32 bit is large enough, do not ask me why 31 th.
  3. int64 maximum bit 2 ^ 63-1 = 18446744073709551616, for it 1000000007 1000000007 2 = 1000000014000000049 does not overflow the int64
  4. Algorithm problem is to check the answer, the answer to the test points can be avoided conflict at the maximum possible.

Therefore, when large numbers of multiplication, as (a * b)% c = ((a% c) * (b% c))% c, so that on both sides are multiplied modulo 1000000007, and then stored in the inside int64 does not overflow, probably Jiang Zi spread, more detailed ignorant friends and I can not think coming.

Guess you like

Origin www.cnblogs.com/daker-code/p/12232592.html