diff --git a/CPP17.md b/CPP17.md index 07e3189..3294986 100644 --- a/CPP17.md +++ b/CPP17.md @@ -35,6 +35,7 @@ C++17 includes the following new library features: - [std::clamp](#stdclamp) - [std::reduce](#stdreduce) - [prefix sum algorithms](#prefix-sum-algorithms) +- [gcd and lcm](#gcd-and-lcm) ## C++17 Language Features @@ -590,6 +591,15 @@ std::transform_exclusive_scan(std::cbegin(a), std::cend(a), std::ostream_iterator{ std::cout, " " }, 0, std::plus<>{}, times_ten); // 0 10 30 ``` +### GCD and LCM +Greatest common divisor (GCD) and least common multiple (LCM). +```c++ +const int p = 9; +const int q = 3; +std::gcd(p, q); // == 3 +std::lcm(p, q); // == 9 +``` + ## Acknowledgements * [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features. * [C++ Rvalue References Explained](http://thbecker.net/articles/rvalue_references/section_01.html) - a great introduction I used to understand rvalue references, perfect forwarding, and move semantics. diff --git a/README.md b/README.md index 90f33cc..ead9967 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ C++17 includes the following new library features: - [std::clamp](#stdclamp) - [std::reduce](#stdreduce) - [prefix sum algorithms](#prefix-sum-algorithms) +- [gcd and lcm](#gcd-and-lcm) C++14 includes the following new language features: - [binary literals](#binary-literals) @@ -1254,6 +1255,15 @@ std::transform_exclusive_scan(std::cbegin(a), std::cend(a), std::ostream_iterator{ std::cout, " " }, 0, std::plus<>{}, times_ten); // 0 10 30 ``` +### GCD and LCM +Greatest common divisor (GCD) and least common multiple (LCM). +```c++ +const int p = 9; +const int q = 3; +std::gcd(p, q); // == 3 +std::lcm(p, q); // == 9 +``` + ## C++14 Language Features ### Binary literals