最大公約数 (integer/gcd.cpp)
- category: integer
-
View this file on GitHub
- Last commit date: 2020-04-06 23:03:06+09:00
Verified with
Code
#ifndef H_gcd
#define H_gcd
/**
* @brief 最大公約数
* @author えびちゃん
*/
#include <utility>
template <typename Tp>
Tp gcd(Tp m, Tp n) {
while (n) std::swap(m %= n, n);
return m;
}
#endif /* !defined(H_gcd) */
#line 1 "integer/gcd.cpp"
/**
* @brief 最大公約数
* @author えびちゃん
*/
#include <utility>
template <typename Tp>
Tp gcd(Tp m, Tp n) {
while (n) std::swap(m %= n, n);
return m;
}