快速幂水过,贴一下模版。
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.
时间: 2024-10-31 22:09:25