Speed up development with full-stack environments for every branch.

Learn More

Factorial function using GMP [PHP]

39 Runs 183 Views 25 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php
/*
 * PHP GMP - Factorial function using GMP
 */

//This will calculate factorial of 1000 (pretty big number) very fast. 
function fact($x) {
    $return = 1;
    for ($i = 2; $i <= $x; $i++) {
        $return = gmp_mul($return, $i);
    }
    return $return;
}

echo gmp_strval(fact(1000));
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).