大数求余

关于c大数求余
(a * b) % c = ((a % c) * (b % c)) % c
(a + b) % c = ((a % c) + (b % c)) % c
应用这些原理
大数用字符数组保存,对每一位进行求余
大数可以分开算:
比如:
m=123
123 = (1*10 + 2)*10 + 3
m%n = 123%n = (((1%n * 10%n + 2%n)%n * 10%n) % n + 3%n)%n
这样每一步都不会溢出了

Leave a Reply

Your email address will not be published. Required fields are marked *