我在Pascal中使用這個大整數的庫,但我在使用modulo
函數時遇到了問題。誰能幫忙?如何在該庫中使用模函數?
我的代碼:
a = b modulo(c);
這裏是圖書館的位置:http://www.delphiforfun.org/programs/library/big_integers.htm
{ ***************** Modulo ************* }
procedure TInteger.Modulo(const I2: TInteger);
{ Modulo (remainder after division) - by TInteger }
var
k: int64;
imod3: TInteger;
begin
if high(I2.fDigits) = 0 then begin
divmodsmall(I2.Sign * I2.fDigits[0], k);
assignsmall(k);
end
else
begin
imod3:= GetNextScratchPad;
DivideRem(I2, imod3);
Assign(imod3);
ReleaseScratchPad(imod3);
end;
end;
爲什麼這個不行?: 也是爲什麼犯規這項工作?:
var
P, Q, N, E, D,i: TInteger;
Eing, Cout: TInteger;
begin
E := 3;
D := 27;
N := 55;
writeln(N.Modulo(E));
請[edit]並定義*我有問題* –
FWIW,@moddersapprentice,如果您想要快速的BigIntegers,請試試我的[BigIntegers.pas](http://www.rvelthuis.de/programs/bigintegers.html )單位。它使用起來更容易,並且可以使用操作員,例如'i3:= i1 mod i2;'。它也有一個'DivMod'過程,同時返回商和餘數。我的BigIntegers是不可變的,所以他們不會「修改自己」,也不需要分配內存,也不需要釋放它們。你可以像使用普通整數一樣使用它們。 –