RosettaCodeData/Task/Factorial/Pascal/factorial-3.pas

34 lines
741 B
ObjectPascal
Raw Permalink Normal View History

2025-06-11 20:16:52 -04:00
program GMPfact;
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
{$mode objfpc}
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
uses
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
gmp
;
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
function Factorial(n: qword): string;
var
ResultMPZ: mpz_t;
i: qword;
begin
mpz_init_set_ui(ResultMPZ, 1);
for i := 2 to n do
mpz_mul_ui(ResultMPZ, ResultMPZ, i);
Result := mpz_get_str(nil, 10, ResultMPZ);
mpz_clear(ResultMPZ);
end;
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
var
N : integer = 101 ;
Fact : string ;
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
begin
Fact := Factorial(101);
writeln( N ,'! = ', Fact);
end. (*) GMPfact (*)
2023-07-01 11:58:00 -04:00
Output:
2025-06-11 20:16:52 -04:00
101! = 9425947759838359420851623124482936749562312794702543768327889353416977599316221476503087861591808346911623490003549599583369706302603264000000000000000000000000