HNOI2008越狱(快速幂)

时间:2014-06-02 13:29:03   收藏:0   阅读:284

快速幂水过,贴一下模版。

bubuko.com,布布扣
const mo=100003;
var x,y,n,m:int64;
function power(num,times:int64):int64;
 var temp:int64;
 begin
 if times=1 then exit(num);
 temp:=power(num,times>>1);
 power:=(temp*temp) mod mo;
 if times and 1=1 then power:=(power*num) mod mo;
 end;
procedure main;
 begin
 readln(m,n);
 x:=power(m,n);
 y:=power(m-1,n-1);
 y:=(y*m) mod mo;
 writeln((x-y+mo) mod mo);
 end;
begin
 main;
end.
             
bubuko.com,布布扣

 

HNOI2008越狱(快速幂),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!