当前位置: 首页>>代码示例>>PHP>>正文


PHP gmp_prob_prime函数代码示例

本文整理汇总了PHP中gmp_prob_prime函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_prob_prime函数的具体用法?PHP gmp_prob_prime怎么用?PHP gmp_prob_prime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gmp_prob_prime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: nextPrime

 /**
  * Finds next strong pseudoprime number, following after $num
  *
  * @param gmp resource $num
  * @return gmp resource
  * @access public
  */
 function nextPrime($num)
 {
     if (!gmp_cmp(gmp_mod($num, 2), 0)) {
         $num = gmp_sub($num, 1);
     }
     do {
         $num = gmp_add($num, 2);
     } while (!gmp_prob_prime($num));
     return $num;
 }
开发者ID:KICHIRO20,项目名称:-Myproject_part1-,代码行数:17,代码来源:GMP.php

示例2: get_prime_number

 function get_prime_number()
 {
     $primos = 0;
     $numeros = 0;
     do {
         $aux = gmp_prob_prime($numeros);
         if ($aux == 2) {
             $primos++;
         }
         $numeros++;
     } while ($primos <= 10001);
     return $numeros;
 }
开发者ID:wildneybrasil,项目名称:sexlog,代码行数:13,代码来源:index.php

示例3: calcularPrimo

 protected function calcularPrimo()
 {
     $x = 0;
     $i = 0;
     while ($i < 10001) {
         if ($this->isImpar($x) || $x == 2) {
             if (gmp_prob_prime($x) == 2) {
                 $primo = $x;
                 $i++;
             }
         }
         $x++;
     }
     return $primo;
 }
开发者ID:h1bertobarbosa,项目名称:teste_x,代码行数:15,代码来源:Controller.php

示例4: isPrime

 /**
  * Checks a numer to see if it's prime
  *
  * Assuming the $t parameter is not set, this function has an error rate of 2**-80.  The main motivation for the
  * $t parameter is distributability.  Math_BigInteger::randomPrime() can be distributed across multiple pageloads
  * on a website instead of just one.
  *
  * @param Math_BigInteger $t
  * @return bool
  * @access public
  * @internal Uses the
  *     {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}.  See
  *     {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}.
  */
 function isPrime($t = false)
 {
     $length = strlen($this->toBytes());
     if (!$t) {
         // see HAC 4.49 "Note (controlling the error probability)"
         // @codingStandardsIgnoreStart
         if ($length >= 163) {
             $t = 2;
         } else {
             if ($length >= 106) {
                 $t = 3;
             } else {
                 if ($length >= 81) {
                     $t = 4;
                 } else {
                     if ($length >= 68) {
                         $t = 5;
                     } else {
                         if ($length >= 56) {
                             $t = 6;
                         } else {
                             if ($length >= 50) {
                                 $t = 7;
                             } else {
                                 if ($length >= 43) {
                                     $t = 8;
                                 } else {
                                     if ($length >= 37) {
                                         $t = 9;
                                     } else {
                                         if ($length >= 31) {
                                             $t = 12;
                                         } else {
                                             if ($length >= 25) {
                                                 $t = 15;
                                             } else {
                                                 if ($length >= 18) {
                                                     $t = 18;
                                                 } else {
                                                     $t = 27;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // @codingStandardsIgnoreEnd
     }
     // ie. gmp_testbit($this, 0)
     // ie. isEven() or !isOdd()
     switch (MATH_BIGINTEGER_MODE) {
         case MATH_BIGINTEGER_MODE_GMP:
             return gmp_prob_prime($this->value, $t) != 0;
         case MATH_BIGINTEGER_MODE_BCMATH:
             if ($this->value === '2') {
                 return true;
             }
             if ($this->value[strlen($this->value) - 1] % 2 == 0) {
                 return false;
             }
             break;
         default:
             if ($this->value == array(2)) {
                 return true;
             }
             if (~$this->value[0] & 1) {
                 return false;
             }
     }
     static $primes, $zero, $one, $two;
     if (!isset($primes)) {
         $primes = array(3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997);
         if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
             for ($i = 0; $i < count($primes); ++$i) {
                 $primes[$i] = new Math_BigInteger($primes[$i]);
             }
         }
         $zero = new Math_BigInteger();
         $one = new Math_BigInteger(1);
         $two = new Math_BigInteger(2);
     }
//.........这里部分代码省略.........
开发者ID:selectSIFISO,项目名称:.comsite,代码行数:101,代码来源:BigInteger.php

示例5: testVerificarNumero2EPrimo

 public function testVerificarNumero2EPrimo()
 {
     $this->assertEquals(2, gmp_prob_prime(2));
 }
开发者ID:h1bertobarbosa,项目名称:teste_x,代码行数:4,代码来源:Etapa1Test.php

示例6: gmp_pow

$pow1 = gmp_pow("2", 31);
echo gmp_strval($pow1) . "\n";
$pow2 = gmp_pow("0", 0);
echo gmp_strval($pow2) . "\n";
$pow3 = gmp_pow("2", -1);
// Negative exp, generates warning
echo gmp_strval($pow3) . "\n";
// gmp_powm
$pow1 = gmp_powm("2", "31", "2147483649");
echo gmp_strval($pow1) . "\n";
// gmp_prob_prime
echo gmp_prob_prime("6") . "\n";
// definitely not a prime
echo gmp_prob_prime("1111111111111111111") . "\n";
// probably a prime
echo gmp_prob_prime("11") . "\n";
// definitely a prime
// gmp_random -- not implemented
// gmp_scan0
// "0" bit is found at position 3. index starts at 0
$s1 = gmp_init("10111", 2);
echo gmp_scan0($s1, 0) . "\n";
// "0" bit is found at position 7. index starts at 5
$s2 = gmp_init("101110000", 2);
echo gmp_scan0($s2, 5) . "\n";
// gmp_scan1
// "0" bit is found at position 3. index starts at 0
$s1 = gmp_init("01000", 2);
echo gmp_scan1($s1, 0) . "\n";
// "0" bit is found at position 7. index starts at 5
$s2 = gmp_init("01000001111", 2);
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php

示例7: is_prime

 public static function is_prime($n)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         return gmp_prob_prime($n);
     } elseif (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
         self::$miller_rabin_test_count = 0;
         $t = 40;
         $k = 0;
         $m = bcsub($n, 1);
         while (bcmod($m, 2) == 0) {
             $k = bcadd($k, 1);
             $m = bcdiv($m, 2);
         }
         for ($i = 0; $i < $t; $i++) {
             $a = bcmath_Utils::bcrand(1, bcsub($n, 1));
             $b0 = self::modular_exp($a, $m, $n);
             if ($b0 != 1 && $b0 != bcsub($n, 1)) {
                 $j = 1;
                 while ($j <= $k - 1 && $b0 != bcsub($n, 1)) {
                     $b0 = self::modular_exp($b0, 2, $n);
                     if ($b0 == 1) {
                         self::$miller_rabin_test_count = $i + 1;
                         return false;
                     }
                     $j++;
                 }
                 if ($b0 != bcsub($n, 1)) {
                     self::$miller_rabin_test_count = $i + 1;
                     return false;
                 }
             }
         }
         return true;
     } else {
         throw new ErrorException("Please install BCMATH or GMP");
     }
 }
开发者ID:zebbra2014,项目名称:bitcoin-webskin-1,代码行数:37,代码来源:PHPCoinAddress.php

示例8: var_dump

<?php

var_dump(gmp_prob_prime(10));
var_dump(gmp_prob_prime("7"));
var_dump(gmp_prob_prime(17));
var_dump(gmp_prob_prime(-31));
var_dump(gmp_prob_prime("172368715471481723"));
var_dump(gmp_prob_prime(10));
var_dump(gmp_prob_prime("7"));
var_dump(gmp_prob_prime(17));
var_dump(gmp_prob_prime(-31));
var_dump(gmp_prob_prime("172368715471481723"));
for ($i = -1; $i < 12; $i++) {
    var_dump(gmp_prob_prime(773 * $i - $i * 7 - 1, $i));
    $n = gmp_init("23476812735411");
    var_dump(gmp_prob_prime(gmp_add($n, $i - 1), $i));
}
$n = gmp_init("19481923");
var_dump(gmp_prob_prime($n));
$n = gmp_init(0);
var_dump(gmp_prob_prime($n));
var_dump(gmp_prob_prime());
var_dump(gmp_prob_prime(array()));
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:24,代码来源:gmp_prob_prime.php

示例9: isPrime

 public function isPrime($t = false)
 {
     $length = strlen($this->toBytes());
     if (!$t) {
         if (163 <= $length) {
             $t = 2;
         } else {
             if (106 <= $length) {
                 $t = 3;
             } else {
                 if (81 <= $length) {
                     $t = 4;
                 } else {
                     if (68 <= $length) {
                         $t = 5;
                     } else {
                         if (56 <= $length) {
                             $t = 6;
                         } else {
                             if (50 <= $length) {
                                 $t = 7;
                             } else {
                                 if (43 <= $length) {
                                     $t = 8;
                                 } else {
                                     if (37 <= $length) {
                                         $t = 9;
                                     } else {
                                         if (31 <= $length) {
                                             $t = 12;
                                         } else {
                                             if (25 <= $length) {
                                                 $t = 15;
                                             } else {
                                                 if (18 <= $length) {
                                                     $t = 18;
                                                 } else {
                                                     $t = 27;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     switch (MATH_BIGINTEGER_MODE) {
         case MATH_BIGINTEGER_MODE_GMP:
             return gmp_prob_prime($this->value, $t) != 0;
         case MATH_BIGINTEGER_MODE_BCMATH:
             if ($this->value === '2') {
                 return true;
             }
             if ($this->value[strlen($this->value) - 1] % 2 == 0) {
                 return false;
             }
             break;
         default:
             if ($this->value == array(2)) {
                 return true;
             }
             if (~$this->value[0] & 1) {
                 return false;
             }
     }
     static $primes;
     static $zero;
     static $one;
     static $two;
     if (!isset($primes)) {
         $primes = array(3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997);
         if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
             for ($i = 0; $i < count($primes); ++$i) {
                 $primes[$i] = new Math_BigInteger($primes[$i]);
             }
         }
         $zero = new Math_BigInteger();
         $one = new Math_BigInteger(1);
         $two = new Math_BigInteger(2);
     }
     if ($this->equals($one)) {
         return false;
     }
     if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
         foreach ($primes as $prime) {
             list(, $r) = $this->divide($prime);
             if ($r->equals($zero)) {
                 return $this->equals($prime);
             }
         }
     } else {
         $value = $this->value;
         foreach ($primes as $prime) {
             list(, $r) = $this->_divide_digit($value, $prime);
             if (!$r) {
                 return count($value) == 1 && $value[0] == $prime;
//.........这里部分代码省略.........
开发者ID:fkssei,项目名称:pigcms10,代码行数:101,代码来源:Math_BigInteger.php

示例10: getPrime

 /**
  * Generates prime number with length $bits_cnt
  * using $random_generator as random generator function.
  *
  * @param int $bits_cnt
  * @param string $rnd_generator
  * @access public
  */
 function getPrime($bits_cnt, $random_generator)
 {
     $bytes_n = intval($bits_cnt / 8);
     $bits_n = $bits_cnt % 8;
     do {
         $str = '';
         for ($i = 0; $i < $bytes_n; $i++) {
             $str .= chr(call_user_func($random_generator) & 0xff);
         }
         $n = call_user_func($random_generator) & 0xff;
         $n |= 0x80;
         $n >>= 8 - $bits_n;
         $str .= chr($n);
         $num = $this->bin2int($str);
         // search for the next closest prime number after [$num]
         if (!gmp_cmp(gmp_mod($num, '2'), '0')) {
             $num = gmp_add($num, '1');
         }
         while (!gmp_prob_prime($num)) {
             $num = gmp_add($num, '2');
         }
     } while ($this->bitLen($num) != $bits_cnt);
     return $num;
 }
开发者ID:382309009,项目名称:SC-API,代码行数:32,代码来源:GMP.php

示例11: isPrime

 public function isPrime($number)
 {
     return gmp_prob_prime($number) ? true : false;
 }
开发者ID:kemoycampbell,项目名称:PHP-RSA,代码行数:4,代码来源:GMP.php

示例12: isPrime

 /**
  * @param int $number
  */
 public static function isPrime($number)
 {
     // Uses Miller-Rabin's probabilistic test
     // https://en.wikipedia.org/wiki/Miller-Rabin_primality_test
     return gmp_prob_prime($number) !== 0;
 }
开发者ID:tomzx,项目名称:project-euler,代码行数:9,代码来源:IntegerFactorization.php

示例13: isPrime

 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\MathAdapterInterface::isPrime()
  */
 public function isPrime($n)
 {
     $prob = gmp_prob_prime(gmp_init($n, 10));
     if ($prob > 0) {
         return true;
     }
     return false;
 }
开发者ID:sbwdlihao,项目名称:phpecc,代码行数:12,代码来源:Gmp.php

示例14:

# numero_primo
<?php 
//exemplo com o numero 10.
$numero = 10;
if (gmp_prob_prime($numero)) {
    print 'É primo';
} else {
    print 'Não é primo';
}
开发者ID:Aloisio1Augusto2,项目名称:numero_primo,代码行数:9,代码来源:miscellaneous.class.php

示例15:

<?php

/**
 *
 * @Author: Marcelo C Menezes
 * https://github.com/marcelocmenezes
 * 
 * Etapa 1
 *
 */
$contador = 0;
for ($i = 2; $i <= 1000000; $i++) {
    if (gmp_prob_prime($i) == 2) {
        $contador++;
        if ($contador == 10001) {
            echo $i;
        }
    }
}
开发者ID:marcelocmenezes,项目名称:sexlog,代码行数:19,代码来源:numeros_primos.php


注:本文中的gmp_prob_prime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。