Forum und email

gmp_gcd

(PHP 4 >= 4.0.4, PHP 5)

gmp_gcd — 最大公約数を計算する

説明

resource gmp_gcd ( resource $a , resource $b )

a と b の最大公約数を計算します。 引数のどちらかまたは両方が負の場合でも結果は常に正となります。

パラメータ

a

It can be either a GMP number resource, or a numeric string given that it is possible to convert the latter to a number.

b

It can be either a GMP number resource, or a numeric string given that it is possible to convert the latter to a number.

返り値

a と b の両方を割り切ることができる正の数を GMP 数で返します。

例

Example#1 gmp_gcd() の例

<?php
$gcd 
= gmp_gcd("12", "21");
echo 
gmp_strval($gcd) . "\n";
?>

上の例の出力は以下となります。

3