std:: gcd
|
定義先ヘッダ
<numeric>
|
||
|
template
<
class
M,
class
N
>
constexpr std:: common_type_t < M, N > gcd ( M m, N n ) ; |
(C++17以降) | |
整数 m と n の 最大公約数 を計算します。
M
または
N
のいずれかが整数型でない場合、あるいはどちらかが(possibly cv-qualified)
bool
である場合、プログラムは不適格(ill-formed)です。
| m | または | n | のいずれかが型 std:: common_type_t < M, N > の値として表現できない場合、動作は未定義です。
目次 |
パラメータ
| m, n | - | 整数値 |
戻り値
m と n が両方ともゼロの場合、ゼロを返します。それ以外の場合、 | m | と | n | の最大公約数を返します。
例外
例外を送出しません。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_gcd_lcm
|
201606L
|
(C++17) |
std::gcd
,
std::lcm
|
例
#include <numeric> int main() { constexpr int p{2 * 2 * 3}; constexpr int q{2 * 3 * 3}; static_assert(2 * 3 == std::gcd(p, q)); static_assert(std::gcd( 6, 10) == 2); static_assert(std::gcd( 6, -10) == 2); static_assert(std::gcd(-6, -10) == 2); static_assert(std::gcd( 24, 0) == 24); static_assert(std::gcd(-24, 0) == 24); }
関連項目
|
(C++17)
|
2つの整数の最小公倍数を計算する
(関数テンプレート) |