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 acmost at 2008-08-16 21:06:13 on Problem 3641
__int64 f(int n)     //就是求a^n%p的函数
{
	__int64 i,k,t,re[35];
	if(n==0) return 1;
	for(k=1;;k++)
		if(1<<k>n) break;
	k--;

	t=1<<k;
	re[0]=a%p;
	for(i=1;i<=k;i++)
		re[i]=(re[i-1]*re[i-1])%p;
	if(t==n) return re[k];
	return (re[k]*f(n-t))%p;
}

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