Skip to content

Commit 2328e86

Browse files
GCD and LCM.
1 parent 5a9e635 commit 2328e86

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CPP17.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ C++17 includes the following new library features:
3535
- [std::clamp](#stdclamp)
3636
- [std::reduce](#stdreduce)
3737
- [prefix sum algorithms](#prefix-sum-algorithms)
38+
- [gcd and lcm](#gcd-and-lcm)
3839

3940
## C++17 Language Features
4041

@@ -590,6 +591,15 @@ std::transform_exclusive_scan(std::cbegin(a), std::cend(a),
590591
std::ostream_iterator<int>{ std::cout, " " }, 0, std::plus<>{}, times_ten); // 0 10 30
591592
```
592593
594+
### GCD and LCM
595+
Greatest common divisor (GCD) and least common multiple (LCM).
596+
```c++
597+
const int p = 9;
598+
const int q = 3;
599+
std::gcd(p, q); // == 3
600+
std::lcm(p, q); // == 9
601+
```
602+
593603
## Acknowledgements
594604
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
595605
* [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.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ C++17 includes the following new library features:
6565
- [std::clamp](#stdclamp)
6666
- [std::reduce](#stdreduce)
6767
- [prefix sum algorithms](#prefix-sum-algorithms)
68+
- [gcd and lcm](#gcd-and-lcm)
6869

6970
C++14 includes the following new language features:
7071
- [binary literals](#binary-literals)
@@ -1254,6 +1255,15 @@ std::transform_exclusive_scan(std::cbegin(a), std::cend(a),
12541255
std::ostream_iterator<int>{ std::cout, " " }, 0, std::plus<>{}, times_ten); // 0 10 30
12551256
```
12561257
1258+
### GCD and LCM
1259+
Greatest common divisor (GCD) and least common multiple (LCM).
1260+
```c++
1261+
const int p = 9;
1262+
const int q = 3;
1263+
std::gcd(p, q); // == 3
1264+
std::lcm(p, q); // == 9
1265+
```
1266+
12571267
## C++14 Language Features
12581268

12591269
### Binary literals

0 commit comments

Comments
 (0)