numeric Header
gcd()
- Computes the greatest common divisor of the integers m and n.
int p = 54;
int q = 36;
cout << gcd(p, q); // prints "18"
lcm()
accumulate()
caution
Time Complexity: O(n)
~~ considering that "n" is the number of elements between the starting and ending elements.
Valid for any container.
note
accumulate()
is of 2 types:
int sum = accumulate(start, end, initialValueOf_sum)
// vector "vec" is given
int sum = accumulate(vec.begin(), vec.end(), 0); /* here "0" is initial value of the "sum"; as 'accumulate()' will store the total value in "sum variable" */
cout << sum;
vector<int> v;
int tmp;
while (cin >> tmp)
{
v.emplace_back(tmp);
}
int sum = accumulate(v.begin(), v.end(), 1, multiplies<int>()); // "multiplies" is a predefined function in C++ STL
cout << sum;
TO DO
- accumulate using own defined function
partial_sum()
adjacent_difference()
iota()
reduce()
transform_reduce()
inner_product()
inclusive_scan()
exclusive_scan()
transform_inclusive_scan()
transform_exclusive_scan()
midpoint()
~ C++20
Common mathematical functions <cstdlib>
header
<cstdlib>
is a included inside<numeric>
header
abs(...)
cout << abs((v.begin() - vfind)) << endl;