(gcd(a,b) == axorb)==>b = a-gcd(a,b)

\((gcd(a,b) == axorb)==>b = a-gcd(a,b)\)的证明

\[(gcd(a,b) == axorb)==>b = a-gcd(a,b) \]

证明$$a-b>=gcd(a,b)$$
\(gcd(a,b) = t\),那么\(a = k1*t,b = k2*t\),所以因为\(gcd(a,b) > 0\),所以\(axorb!=0\),假设a > b,所以\(a-b = c*t >= gcd(a,b)\)
证明$$a-b <= axorb$$,
把a,b换成二进制来按每位来考虑,共有四种可能$$(1,0) = (-)1 (xor)1||(1,1) = (-)0(xor)(0)||(0,1) = (-)-1(xor)1||(0,0) = (-)0(xor)0$$所以可以看出\(a-b <= axorb\).
因为\(gcd(a,b) == axorb\),所以有\(a-b == gcd(a,b)\);
题目链接

posted @ 2017-05-15 17:58  sCjTyC  阅读(335)  评论(0编辑  收藏  举报