Beispiel #1
0
 static function use_hint($n)
 {
     $all_hints = self::all_hints();
     $hints =& $all_hints[count($all_hints) - 1];
     if (!safe_get($n, $hints[0])) {
         return;
     }
     // hint does not exist
     $hints[1] &= 1 << $n;
     if (gmp_popcount(gmp_init($hints[1])) > $hints[2]) {
         return;
     }
     // hint already used
     self::set_hints($all_hints);
     return $hints[0][$n];
 }
Beispiel #2
0
$or2 = gmp_or("0xfffffff2", "2");
echo gmp_strval($or2, 16) . "\n";
// gmp_perfect_square
var_dump(gmp_perfect_square("9"));
// 3 * 3, perfect square
var_dump(gmp_perfect_square("7"));
// not a perfect square
// 1234567890 * 1234567890, perfect square
var_dump(gmp_perfect_square("1524157875019052100"));
// gmp_popcount
$pop1 = gmp_init("10000101", 2);
// 3 1's
echo gmp_popcount($pop1) . "\n";
$pop2 = gmp_init("11111110", 2);
// 7 1's
echo gmp_popcount($pop2) . "\n";
// 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";
Beispiel #3
0
<?php

var_dump(gmp_popcount(-1));
var_dump(gmp_popcount(0));
var_dump(gmp_popcount(12123));
var_dump(gmp_popcount("52638927634234"));
var_dump(gmp_popcount("-23476123423433"));
$n = gmp_init("9876546789222");
var_dump(gmp_popcount($n));
var_dump(gmp_popcount(array()));
var_dump(gmp_popcount());
echo "Done\n";