牛牛在线工具

gmp_powm()

收录 8868 个 PHP 函数,含用途说明与用法示例。

gmp_powm()

计算模幂运算,即计算 (base raised to the power exponent) mod modulus

函数名称:gmp_powm() 适用版本:PHP 4 >= 4.0.4, PHP 5, PHP 7 函数描述:gmp_powm() 函数用于计算模幂运算,即计算 (base raised to the power exponent) mod modulus。 用法: gmp_powm ( GMP $base , GMP $exponent , GMP $modulus ) : GMP 参数说明: $base:GMP 类型的基数,可以是一个 GMP 对象或一个可以转换为 GMP 的整数字符串。 $exponent:GMP 类型的指数,可以是一个 GMP 对象或一个可以转换为 GMP 的整数字符串。 $modulus:GMP 类型的模数,可以是一个 GMP 对象或一个可以转换为 GMP 的整数字符串。 返回值: 返回一个 GMP 对象,表示计算结果。 示例: $base = gmp_init("2"); // 创建 GMP 对象,基数为 2 $exponent = gmp_init("10"); // 创建 GMP 对象,指数为 10 $modulus = gmp_init("7"); // 创建 GMP 对象,模数为 7 $result = gmp_powm($base, $exponent, $modulus); echo gmp_strval($result); // 输出结果为 4 在上面的示例中,我们使用 gmp_init() 函数创建了三个 GMP 对象,分别表示基数、指数和模数。然后,我们使用 gmp_powm() 函数对基数进行模幂运算,将结果保存在 $result 变量中。最后,我们使用 gmp_strval() 函数将结果转换为字符串并输出。在本例中,2 的 10 次方除以 7 的余数为 4。