Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:算法绝对牛B,怎么说我错了???跪求更牛人来解释一下!!!

Posted by justkain at 2006-08-15 19:45:25 on Problem 1061
In Reply To:算法绝对牛B,怎么说我错了???跪求更牛人来解释一下!!! Posted by:justkain at 2006-08-15 18:38:33
我的算法解释如下:
对于给定A,B,C;如果满足A+B*N=C*M这一形式,
此式中未知量M周期为对应的B,N的周期为对应的C.

令A'=A%C,B'=B%C,则,化简为:
A'+B'*N=M'*C,M=M'-[A/C]+N*B*[B/C].
由于此时M的周期为B,取M=(M'-[A/C]+N*[B/C])%B.
对上式变形:
-A'+M'*C=N*B',再令A''=A'%B',C''=C%B',再化简:
-A''+M'*C''=N'*B',N=N'-(-[A'/B'])+M'*C*[C/B'].
由于此时N的周期为C,取N=(N'-(-[A'/B'])+M'*[C/B'])%C.
再对上式变形:
A''+N'*B'=M'*B'',...
由上可知,可递归解出结果.见我写的check函数.

函数中涉及到求最大公约数:
解释如下:
给定A,B求最大公约数.
分析一方面A>B,其它也就容易解决.
如果A>B,证T=A%B和B的最大公约数为A和B的最大公约数.
由条件知,A=B*K+T,T<B互质.
设T,B的最大公约数为M,则M<=T<B.
设B=N*M,则T=Q*M,N,Q互质.
A/B=(N*K+Q)/N,由于N,Q互质,故N*K+Q,N互质.
既A,B最大公约数为M,命题得证.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator