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 beyonlin_SCUT at 2008-10-29 11:31:37 on Problem 1284
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:
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