TheAlgorithms/C++ 1.0.0
All the 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 <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | math |
for assert | |
Functions | |
uint64_t | math::lcmSum (const uint16_t &num) |
static void | test () |
int | main () |
Main function. | |
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.
Definition in file lcm_sum.cpp.
int main | ( | void | ) |
|
static |
Function for testing lcmSum function. test cases and assert statement.
void
Definition at line 66 of file lcm_sum.cpp.