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

终于找到正确方法了.

Posted by zhucheng at 2005-12-07 17:25:21 on Problem 2720
In Reply To:用一个不大正确的算法糊弄过去了……谁能给个正确算法的提示? Posted by:frkstyc at 2005-12-04 23:48:59
只需要解决a^m mod n怎么计算,m非常大。
1)如果d=gcd(a,n)等于1,那么由欧拉定理得到原式等于a^(m mod Euler(n)) mod n
Euler()是欧拉函数;
2)d不等于1,那么原式等于((a/d)^m*d*d^(m-1)) mod n
---> ((a/d)^m*d  mod n ) * ( d^(m-1) mod n)  mod n )
分成两部分进行计算 d*((a/d)^m mod (n/d)) 可以用1)解决,因为 a/d和n/d互质。
d^(m-1) mod n  = (d^(m-2) mod (n/d))*d继续递归解决。
粗糙的实现会超时,需要一些细节上的优化。

 

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