Bevor du dir viel Arbeit machst, schau mal hier:
Delphi-Quellcode:
function PowerAndMod(A, E, M: int64): int64;
begin
Result := 0;
if E < 0
then
Exit;
if (M = 1)
or (M = -1)
then
Exit;
if (A = 0)
and (E > 0)
then
Exit;
Result := 1;
try
while E > 0
do
if E
mod 2 <> 0
then // Odd
begin
Result := (Result * A)
mod M;
E := E - 1;
end
else
begin
A := (A * A)
mod M;
E := E
div 2;
end;
except
raise Exception.Create('
Int64 Overflow');
end;
end;