主要是用来求两个大数a,b进行 + or - or * 后对某个数mod求余
比如a+b或者a*b超过了long long int ,就要用取模运算把值限制在0~mod内
加法
(a+b)%mod=(a%mod+b%mod)%mod;
减法
(a-b)%mod=(a%mod-b%mod)%mod;
乘法
(a * b)%mod=(a%mod) * (b%mod)%mod;
除法 (用到逆元,尚未了解)
当两个数a和b(a>b)
(a-b)%mod=(a%mod-b%mod)%mod;
如果a%mod<b%mod就要用
(a%mod-b%mod+mod)%mod;
例如:
a=12,b=9,mod=10;
a%mod=2,b%mod=9;
因为2-9<0,得到的是负数,之前a-b是正数
所以应该是(a%mod-b%mod+mod)%mod;
就是(12-9)%10=(12%10-9%10+10)%10=3%10=3