The 5th Annual China PHP Conference


Exemplo #1 Função factorial usando GMP

function fact($x
$return 1;
    for (
$i=2$i $x$i++) {
$return gmp_mul($return$i);

gmp_strval(fact(1000)) . "\n";

Isto irá calcular o fatorial de 1000 (um número grande) muito rápido.

add a note add a note

User Contributed Notes 1 note

Juliano Barreto
1 year ago
I forgot to mention. You need (obviously) to remove the gmp function for a usual one. Like this:

function fact($num)
    $res = 1;
    for ($n = $num; $n >= 1; $n--)
        $res = $res*$n;
    return $res;
To Top