HNOI2008越狱(快速幂)

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

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.
             

 

posted @ 2014-06-01 10:18  ZYF-ZYF  Views(170)  Comments(0Edit  收藏  举报