Working with large numbers in PHP

前端 未结 8 976
一个人的身影
一个人的身影 2020-11-22 11:22

To use modular exponentiation as you would require when using the Fermat Primality Test with large numbers (100,000+), it calls for some very large calculations.

Whe

8条回答
  •  庸人自扰
    2020-11-22 12:14

    I wrote a very small code for you that will surely work in case of big numbers-

    ";
        echo "mod : ".$mod;
    
        /* Output:
            x : 3915505476
            mod : 2968
        */
    ?>
    

    You simply have to use strings for storing big numbers and to operate on them use GMP functions in PHP.

    You may check some good GMP functions in the official PHP manual here- http://php.net/manual/en/ref.gmp.php

提交回复
热议问题