gmp_lcm()是 PHP 中的內置函數,用於計算兩個或多個整數的最小公倍數 (LCM)。
用法:
gmp_lcm(GMP|int|string $num1, GMP|int|string $num2): GMP
Parameters: 該函數接受兩個參數,如下所述。
- $num1: 表示第一個整數的 GMP 編號資源。
- $num2: 表示第二個整數的 GMP 編號資源。
返回值: gmp_lcm()函數返回用戶提供的兩個整數的lcm。
程序1:下麵的程序演示了gmp_lcm()函數。
PHP
<?php
// Assuming you have the GMP
// extension enabled
$a = gmp_init(12);
$b = gmp_init(18);
$lcm = gmp_lcm($a, $b);
echo "LCM of $a and $b is: $lcm\n";
?>
輸出:
LCM of 12 and 18 is: 36
程序2:下麵的程序演示了gmp_lcm()函數。
PHP
<?php
// Assuming you have the GMP
// extension enabled
$a = gmp_init(12);
$b = gmp_init(18);
$c = gmp_init(24);
$lcm_of_three = gmp_lcm($a, gmp_lcm($b, $c));
echo "LCM of $a, $b, and $c is: $lcm_of_three\n";
?>
輸出:
LCM of 12, 18, and 24 is: 72
參考:https://www.php.net/manual/en/function.gmp-lcm.php
相關用法
- PHP gmp_lcm()用法及代碼示例
- PHP gmp_legendre()用法及代碼示例
- PHP gmp_binomial()用法及代碼示例
- PHP gmp_div()用法及代碼示例
- PHP gmp_fact()用法及代碼示例
- PHP gmp_init()用法及代碼示例
- PHP gmp_kronecker()用法及代碼示例
- PHP gmp_testbit()用法及代碼示例
- PHP gmp_abs()用法及代碼示例
- PHP gmp_and()用法及代碼示例
- PHP gmp_clrbit()用法及代碼示例
- PHP gmp_cmp()用法及代碼示例
- PHP gmp_com()用法及代碼示例
- PHP gmp_div_q()用法及代碼示例
- PHP gmp_div_qr()用法及代碼示例
- PHP gmp_div_r()用法及代碼示例
- PHP gmp_divexact()用法及代碼示例
- PHP gmp_export()用法及代碼示例
- PHP gmp_gcd()用法及代碼示例
- PHP gmp_gcdext()用法及代碼示例
- PHP gmp_hamdist()用法及代碼示例
- PHP gmp_import()用法及代碼示例
- PHP gmp_intval()用法及代碼示例
- PHP gmp_jacobi()用法及代碼示例
- PHP gmp_mod()用法及代碼示例
注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP gmp_lcm() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。