孙子定理是中国古代求解一次同余式组的方法。是数论中一个重要定理。一元线性同余方程组问题最早可见于中国南北朝时期(公元5世纪)的数学著作《孙子算经》卷下第二十六题,叫做“物不知数”问题,原文如下:
有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二。问物几何?即,一个整数除以三余二,除以五余三,除以七余二,求这个整数。《孙子算经》中首次提到了同余方程组问题,以及以上具体问题的解法,因此在中文数学文献中也会将中国剩余定理称为孙子定理。
给出n个同余式, 求满足所有式子的一个最小解,一般形式如下:
求解x的最小值,其中, 是互质的, 如果不互质,应该用其他方法求解.
中国剩余定理给出求解公式:
设,
对于则构造同余式
其中 都是已知的, 可以用exgcd求出, 这是最主要的一步
求解方法 :https://blog.csdn.net/qq_41505957/article/details/101515687
都已知, 可以求出x.
举个例子:
那么
M = 17*13*7=1547 ,求出
构造同余方程
用扩展欧几里得解得
x=13*91*3 + 4*119*(-6) + 5*221*2 = 2903