GCD and LCM.

This commit is contained in:
Anthony Calandra
2023-02-20 20:22:40 -05:00
parent 5a9e63549e
commit 2328e86239
2 changed files with 20 additions and 0 deletions

View File

@@ -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<int>{ 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.