gmp_perfect_power


gmp apg

CHECKS if a number is a perfect power.


This function is only available in PHP 7.3.0 or later






This function returns TRUE on success or FALSE on fail.



<?php

bool gmp_perfect_power 
GMP|int|string $num )


where,

$num The number to be checked

?>
 

$num


The number to be checked.



  1 EXERCISE   

<?php

function checkifppw01 $a01 )
{
    if(
PHP_VERSION_ID 70300)
    {
        echo 
'This function is not available to this PHP version!<br><br>';
        exit;
    }
    
    if (
gmp_perfect_power($a01) == TRUE)
    {
        echo 
$a01 ' is a perfect power!<br><br>';
    }
    else
    {
         echo 
$a01 ' is NOT a perfect power!<br><br>';
    }
}

$a01a = [ '0200000''0200001''0x10000''0x1000A'6553665537  ];

foreach(
$a01a as $a01)
{
checkifppw01($a01);
}    

?> 

 RESULT   

0200000 is a perfect power!

0200001 is NOT a perfect power!

0x10000 is a perfect power!

0x1000A is NOT a perfect power!

65536 is a perfect power!

65537 is NOT a perfect power!


  2 EXERCISE   

<?php

function checkifppw02 $a02 )
{
    if(
PHP_VERSION_ID 70300)
    {
        echo 
'This function is not available to this PHP version!<br><br>';
        exit;
    }
    
    if (
gmp_perfect_power($a02) == TRUE)
    {
        echo 
$a02 ' is a perfect power!<br><br>';
    }
    else
    {
         echo 
$a02 ' is NOT a perfect power!<br><br>';
    }
}

$a02a = [ -8, -6, -4, -2, -1012468,
                 
"7442665456261594668083173595997"
                 
"7442665456261594668083173595998",
                  
PHP_INT_MIN,
                  
PHP_INT_MAX ];

foreach(
$a02a as $a02)
{
checkifppw02($a02);
}    

?>