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 |
给大家介绍个快的方法。。高手莫笑!!!!__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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator