快速幂不多说,当两个int64相乘时可能会爆掉,所以运用快速幂的的思想快速求出
function cal(x,y:int64):int64;
var
ans:int64;
temp:int64;
begin
ans:=0;
temp:=x;
while y<>0 do
begin
if y and 1=1 then ans:=(ans+temp)mod m;
temp:=(temp+temp)mod m;
y:=y shr 1;
end;
exit(ans);
end;