Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数论中有讲In Reply To:求助:怎么处理超过整数数值范围的数对23取模的情况?例:pow(9,10)就超过了int型的范围,再对23取模就成负数了 Posted by:rainstorm at 2007-08-16 21:02:45 //a^b mod n int modExp(int a, int b, int n) { int t = 1, y = a; while(b != 0) { y %= n; if(b % 2 == 1) t = t % n * y % n; y = y * y % n; b = b >> 1; } return t; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator