|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
An algorithm to calculate the sum of LCM: \(\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\). More...
#include <cassert>#include <iostream>#include <vector>Namespaces | |
| namespace | math |
| for std::rand | |
Functions | |
| uint64_t | math::lcmSum (const uint16_t &num) |
| static void | test () |
| int | main () |
| Main function. More... | |
An algorithm to calculate the sum of LCM: \(\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\).
An algorithm to calculate the sum of LCM: \(\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\) where \(\mathrm{LCM}(i,n)\) denotes the Least Common Multiple of the integers i and n. For n greater than or equal to 1. The value of the sum is calculated by formula:
\[ \sum\mathrm{LCM}(i, n) = \frac{1}{2} \left[\left(\sum (d * \mathrm{ETF}(d)) + 1\right) * n\right] \]
where \mathrm{ETF}(i) represents Euler totient function of i.
| int main | ( | void | ) |
|
static |
Function for testing lcmSum function. test cases and assert statement.
void