Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.
C++ Boost

gcd_lcm - GCD and LCM


detail/gcd_lcm.hpp provides two generic integer algorithms: greatest common divisor and least common multiple.


namespace details {
namespace pool {

template <typename Integer>
Integer gcd(Integer A, Integer B);

template <typename Integer>
Integer lcm(Integer A, Integer B);

} // namespace pool
} // namespace details


Symbol Table
IntegerAn integral type
A, BValues of type Integer
ExpressionResult TypePreconditionNotes
gcd(A, B)IntegerA > 0 && B > 0Returns the greatest common divisor of A and B
lcm(A, B)IntegerA > 0 && B > 0Returns the least common multiple of A and B

Implementation Notes

For faster results, ensure A > B



Future Directions

This header may be replaced by a Boost algorithms library.

Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)

This file can be redistributed and/or modified under the terms found in copyright.html

This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.