基本模运算

2019-04-13 11:58发布

1.概念:模运算是指取模运算,即求m/n的余数。模运算有许多基本规则,熟练掌握可以更好的编程。2.交换律:                        (a + b) % m = (b + a) % m
                        (a * b) % m = (b * a) % m
3.结合律:                        [(a+b)%m+c]%m = [a+(b+c)%m]%m
                        [(a*b)%m*c]%m = [(b*c)%m*a]%m
4.分配律:                        [(a+b)%m * c] % m = [(a*c)%m + (b*c)%m] % m
                        (a+b)%m = (a%m + b%m)%m
                        (a - b)%m = (a%m - b%m)%m
                        (a*b)%m = (a%m * b%m)%m
                        a^b % m = (a%m)^b % m
5.重要结论: