From 2854a463e198d1dc5810358f68c0536ee5f236c5 Mon Sep 17 00:00:00 2001 From: chestamittal Date: Tue, 20 Oct 2020 00:26:45 +0530 Subject: [PATCH 01/20] add lcm_sum.cpp --- math/lcm_sum.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 math/lcm_sum.cpp diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp new file mode 100644 index 000000000..2414f2d3a --- /dev/null +++ b/math/lcm_sum.cpp @@ -0,0 +1,90 @@ +/** + * @file + * @brief An algorithm to calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where 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: + * ∑LCM(i, n) = ((∑(d * ETF(d)) + 1) * n) / 2 + * + * @author [Chesta Mittal](https://github.com/chestamittal) + */ + +#include // for std::cin std::cout +#include // for assert +#include // dor std::vector + +/** + * Function to compute sum of euler totients in sumOfEulerTotient vector + * @param num input number + * @returns int + */ +int lcmSum(int num) { + + int i=0, j=0; + int limit = 1000; + std::vector eulerTotient(limit); + std::vector sumOfEulerTotient(limit); + + // storing initial values in eulerTotient vector + for(i=1; i<=limit; i++) { + eulerTotient[i] = i; + } + + // applying totient sieve + for(i=2; i<=limit; i++) { + if(eulerTotient[i] == i) { + for(j=i; j<=limit; j+=i) { + eulerTotient[j] = eulerTotient[j]/i; + eulerTotient[j] = eulerTotient[j]*(i-1); + } + } + } + + // computing sum of euler totients + for(i=1; i<=limit; i++) { + for(j=i; j <=limit; j+=i) { + sumOfEulerTotient[j] += eulerTotient[i]*i; + } + } + + return ((sumOfEulerTotient[num] + 1 ) * num) / 2; +} + +/** + * Function for testing lcmSum function. + * test cases and assert statement. + * @returns `void` +*/ +static void test() { + int n = 2; + int test_1 = lcmSum(n); + assert(test_1 == 4); + std::cout << "Passed Test 1!" << std::endl; + + n = 5; + int test_2 = lcmSum(n); + assert(test_2 == 55); + std::cout << "Passed Test 2!" << std::endl; + + n = 10; + int test_3 = lcmSum(n); + assert(test_3 == 320); + std::cout << "Passed Test 3!" << std::endl; + + n = 11; + int test_4 = lcmSum(n); + assert(test_4 == 616); + std::cout << "Passed Test 4!" << std::endl; + + n = 15; + int test_5 = lcmSum(n); + assert(test_5 == 1110); + std::cout << "Passed Test 5!" << std::endl; +} + +/** +* main function +*/ +int main() { + test(); + return 0; +} From d817968d1ad2be6e61790d40328d34a91cf2707c Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 01:39:23 +0530 Subject: [PATCH 02/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 2414f2d3a..12141afd1 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -83,7 +83,7 @@ static void test() { /** * main function -*/ + */ int main() { test(); return 0; From 1e1d11d03e210e142d1f9f9862981d72d5393d76 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 01:39:35 +0530 Subject: [PATCH 03/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 12141afd1..6ccb5abfe 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -85,6 +85,6 @@ static void test() { * main function */ int main() { - test(); + test(); // execute the tests return 0; } From 261960cfb00407e98398b75d4e74bcd9f44aec7d Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 01:39:58 +0530 Subject: [PATCH 04/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 6ccb5abfe..91cd6832e 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -82,7 +82,8 @@ static void test() { } /** -* main function + * @brief Main function + * @returns 0 on exit */ int main() { test(); // execute the tests From 6dc89cc441542b131958fe8b6084fbd118043820 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 01:40:10 +0530 Subject: [PATCH 05/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 91cd6832e..dca5530d2 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -8,14 +8,14 @@ * @author [Chesta Mittal](https://github.com/chestamittal) */ -#include // for std::cin std::cout -#include // for assert -#include // dor std::vector +#include /// for std::cin and std::cout +#include /// for assert +#include /// for std::vector /** * Function to compute sum of euler totients in sumOfEulerTotient vector * @param num input number - * @returns int + * @returns int Sum of LCMs, i.e. ∑LCM(i, num) from i = 1 to num */ int lcmSum(int num) { From 403f44d9245e0587a9ed920f39209c85dd0bd930 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:02:11 +0530 Subject: [PATCH 06/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index dca5530d2..4a317784b 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -61,7 +61,7 @@ static void test() { std::cout << "Passed Test 1!" << std::endl; n = 5; - int test_2 = lcmSum(n); + int test_2 = math::lcmSum(n); assert(test_2 == 55); std::cout << "Passed Test 2!" << std::endl; From 2db80b5066c0eb862c34633e74d00b844b090c2e Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:02:21 +0530 Subject: [PATCH 07/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 4a317784b..950a90c17 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -76,7 +76,7 @@ static void test() { std::cout << "Passed Test 4!" << std::endl; n = 15; - int test_5 = lcmSum(n); + int test_5 = math::lcmSum(n); assert(test_5 == 1110); std::cout << "Passed Test 5!" << std::endl; } From 0978680880f928150f4a98a1913316518bdb3a2f Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:02:32 +0530 Subject: [PATCH 08/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 950a90c17..c27514d02 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -71,7 +71,7 @@ static void test() { std::cout << "Passed Test 3!" << std::endl; n = 11; - int test_4 = lcmSum(n); + int test_4 = math::lcmSum(n); assert(test_4 == 616); std::cout << "Passed Test 4!" << std::endl; From 1c7fe2628525aee717202b9c2c163ac49403260c Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:02:41 +0530 Subject: [PATCH 09/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index c27514d02..bababab9d 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -66,7 +66,7 @@ static void test() { std::cout << "Passed Test 2!" << std::endl; n = 10; - int test_3 = lcmSum(n); + int test_3 = math::lcmSum(n); assert(test_3 == 320); std::cout << "Passed Test 3!" << std::endl; From c89a0e3bf0ff8bcfcb5576bbdd145ed84a28bb0d Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:02:50 +0530 Subject: [PATCH 10/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index bababab9d..46452120e 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -56,7 +56,7 @@ int lcmSum(int num) { */ static void test() { int n = 2; - int test_1 = lcmSum(n); + int test_1 = math::lcmSum(n); assert(test_1 == 4); std::cout << "Passed Test 1!" << std::endl; From 1ebb42185f08c436214556d99a5398dadb638243 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:03:03 +0530 Subject: [PATCH 11/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 46452120e..b29de72de 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -48,6 +48,7 @@ int lcmSum(int num) { return ((sumOfEulerTotient[num] + 1 ) * num) / 2; } +} // namespace math /** * Function for testing lcmSum function. From c7912e7b1be729088aa11a5aeefb308b1db4a46b Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 03:03:12 +0530 Subject: [PATCH 12/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 57 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index b29de72de..ee341bd2b 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -13,41 +13,46 @@ #include /// for std::vector /** - * Function to compute sum of euler totients in sumOfEulerTotient vector - * @param num input number - * @returns int Sum of LCMs, i.e. ∑LCM(i, num) from i = 1 to num + * @namespace math + * @brief Mathematical algorithms */ -int lcmSum(int num) { +namespace math { + /** + * Function to compute sum of euler totients in sumOfEulerTotient vector + * @param num input number + * @returns int Sum of LCMs, i.e. ∑LCM(i, num) from i = 1 to num + */ + int lcmSum(int num) { - int i=0, j=0; - int limit = 1000; - std::vector eulerTotient(limit); - std::vector sumOfEulerTotient(limit); + int i=0, j=0; + int limit = 1000; + std::vector eulerTotient(limit); + std::vector sumOfEulerTotient(limit); - // storing initial values in eulerTotient vector - for(i=1; i<=limit; i++) { - eulerTotient[i] = i; - } + // storing initial values in eulerTotient vector + for(i=1; i<=limit; i++) { + eulerTotient[i] = i; + } - // applying totient sieve - for(i=2; i<=limit; i++) { - if(eulerTotient[i] == i) { - for(j=i; j<=limit; j+=i) { - eulerTotient[j] = eulerTotient[j]/i; - eulerTotient[j] = eulerTotient[j]*(i-1); + // applying totient sieve + for(i=2; i<=limit; i++) { + if(eulerTotient[i] == i) { + for(j=i; j<=limit; j+=i) { + eulerTotient[j] = eulerTotient[j]/i; + eulerTotient[j] = eulerTotient[j]*(i-1); + } } } - } - // computing sum of euler totients - for(i=1; i<=limit; i++) { - for(j=i; j <=limit; j+=i) { - sumOfEulerTotient[j] += eulerTotient[i]*i; + // computing sum of euler totients + for(i=1; i<=limit; i++) { + for(j=i; j <=limit; j+=i) { + sumOfEulerTotient[j] += eulerTotient[i]*i; + } } + + return ((sumOfEulerTotient[num] + 1 ) * num) / 2; } - - return ((sumOfEulerTotient[num] + 1 ) * num) / 2; -} } // namespace math /** From ed033c38b39296a1b4e4136e994d6ce98afc4f1e Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 19 Oct 2020 21:39:00 +0000 Subject: [PATCH 13/20] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 1aaf9dade..4765d74c3 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -140,6 +140,7 @@ * [Gcd Recursive Euclidean](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/gcd_recursive_euclidean.cpp) * [Large Factorial](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/large_factorial.cpp) * [Large Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/large_number.h) + * [Lcm Sum](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/lcm_sum.cpp) * [Least Common Multiple](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/least_common_multiple.cpp) * [Miller Rabin](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/miller_rabin.cpp) * [Modular Inverse Fermat Little Theorem](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/modular_inverse_fermat_little_theorem.cpp) From e466714e27f5c5e2e4482465216ce96b1e1c4a75 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:19:15 +0530 Subject: [PATCH 14/20] Update math/lcm_sum.cpp Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- math/lcm_sum.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index ee341bd2b..d64bcd668 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -1,6 +1,7 @@ /** * @file - * @brief An algorithm to calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) + * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ + * @details An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ where \f$\mathrm{LCM}(i,n)\f$ * 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: * ∑LCM(i, n) = ((∑(d * ETF(d)) + 1) * n) / 2 From b1e2d1ed8e10bf51241a65b64ef9d98abad5271b Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:19:29 +0530 Subject: [PATCH 15/20] Update math/lcm_sum.cpp Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- math/lcm_sum.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index d64bcd668..d9c61fb95 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -4,7 +4,9 @@ * @details An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ where \f$\mathrm{LCM}(i,n)\f$ * 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: - * ∑LCM(i, n) = ((∑(d * ETF(d)) + 1) * n) / 2 + * \f[ + * \sum\mathrm{LCM}(i, n) = \frac{1}{2} \left[\left(\sum (d * \mathrm{ETF}(d)) + 1\right) * n\right] + * \f] * * @author [Chesta Mittal](https://github.com/chestamittal) */ @@ -26,19 +28,18 @@ namespace math { int lcmSum(int num) { int i=0, j=0; - int limit = 1000; - std::vector eulerTotient(limit); - std::vector sumOfEulerTotient(limit); + std::vector eulerTotient(num+1); + std::vector sumOfEulerTotient(num+1); // storing initial values in eulerTotient vector - for(i=1; i<=limit; i++) { + for(i=1; i<=num; i++) { eulerTotient[i] = i; } // applying totient sieve - for(i=2; i<=limit; i++) { + for(i=2; i<=num; i++) { if(eulerTotient[i] == i) { - for(j=i; j<=limit; j+=i) { + for(j=i; j<=num; j+=i) { eulerTotient[j] = eulerTotient[j]/i; eulerTotient[j] = eulerTotient[j]*(i-1); } @@ -46,8 +47,8 @@ namespace math { } // computing sum of euler totients - for(i=1; i<=limit; i++) { - for(j=i; j <=limit; j+=i) { + for(i=1; i<=num; i++) { + for(j=i; j <=num; j+=i) { sumOfEulerTotient[j] += eulerTotient[i]*i; } } From 1af94ccf6fe788e2c2f4ff3fa050a0008d81fff8 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Wed, 21 Oct 2020 22:15:06 +0530 Subject: [PATCH 16/20] Update math/lcm_sum.cpp Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index d9c61fb95..60bac3283 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -1,6 +1,6 @@ /** * @file - * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ + * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\f$ * @details An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ where \f$\mathrm{LCM}(i,n)\f$ * 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: From 997404b48aa18eb42c3570fa183bf99f0bacc957 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Wed, 21 Oct 2020 22:15:20 +0530 Subject: [PATCH 17/20] Update math/lcm_sum.cpp Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- math/lcm_sum.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 60bac3283..dd9667b49 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -1,13 +1,13 @@ /** * @file - * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\f$ + * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ * @details An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ where \f$\mathrm{LCM}(i,n)\f$ * 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: * \f[ * \sum\mathrm{LCM}(i, n) = \frac{1}{2} \left[\left(\sum (d * \mathrm{ETF}(d)) + 1\right) * n\right] * \f] - * + * where \mathrm{ETF}(i) represents Euler totient function of i. * @author [Chesta Mittal](https://github.com/chestamittal) */ @@ -25,11 +25,11 @@ namespace math { * @param num input number * @returns int Sum of LCMs, i.e. ∑LCM(i, num) from i = 1 to num */ - int lcmSum(int num) { + uint64_t lcmSum(uint64_t num) { - int i=0, j=0; - std::vector eulerTotient(num+1); - std::vector sumOfEulerTotient(num+1); + uint64_t i=0, j=0; + std::vector eulerTotient(num+1); + std::vector sumOfEulerTotient(num+1); // storing initial values in eulerTotient vector for(i=1; i<=num; i++) { @@ -63,28 +63,28 @@ namespace math { * @returns `void` */ static void test() { - int n = 2; - int test_1 = math::lcmSum(n); + uint64_t n = 2; + uint64_t test_1 = math::lcmSum(n); assert(test_1 == 4); std::cout << "Passed Test 1!" << std::endl; n = 5; - int test_2 = math::lcmSum(n); + uint64_t test_2 = math::lcmSum(n); assert(test_2 == 55); std::cout << "Passed Test 2!" << std::endl; n = 10; - int test_3 = math::lcmSum(n); + uint64_t test_3 = math::lcmSum(n); assert(test_3 == 320); std::cout << "Passed Test 3!" << std::endl; n = 11; - int test_4 = math::lcmSum(n); + uint64_t test_4 = math::lcmSum(n); assert(test_4 == 616); std::cout << "Passed Test 4!" << std::endl; n = 15; - int test_5 = math::lcmSum(n); + uint64_t test_5 = math::lcmSum(n); assert(test_5 == 1110); std::cout << "Passed Test 5!" << std::endl; } From 288d3582b62ea83e5d582c213fa79aefc472dd07 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Thu, 22 Oct 2020 02:17:34 +0530 Subject: [PATCH 18/20] Update math/lcm_sum.cpp Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- math/lcm_sum.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index dd9667b49..a27f6d239 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -1,7 +1,7 @@ /** * @file - * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ - * @details An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + .. + \mathrm{LCM}(n,n)\f$ where \f$\mathrm{LCM}(i,n)\f$ + * @brief An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\f$ + * @details An algorithm to calculate the sum of LCM: \f$\mathrm{LCM}(1,n) + \mathrm{LCM}(2,n) + \ldots + \mathrm{LCM}(n,n)\f$ where \f$\mathrm{LCM}(i,n)\f$ * 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: * \f[ From 57729bf37fe06dd7e34569894b56bee77d653adf Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Mon, 26 Oct 2020 00:00:43 +0530 Subject: [PATCH 19/20] Update math/lcm_sum.cpp Co-authored-by: David Leal --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index a27f6d239..4800ed66a 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -25,7 +25,7 @@ namespace math { * @param num input number * @returns int Sum of LCMs, i.e. ∑LCM(i, num) from i = 1 to num */ - uint64_t lcmSum(uint64_t num) { + uint64_t lcmSum(uint16_t num) { uint64_t i=0, j=0; std::vector eulerTotient(num+1); From 2d415763d7f456fc5313bee05dfe746e4614dd67 Mon Sep 17 00:00:00 2001 From: chestamittal <53469607+chestamittal@users.noreply.github.com> Date: Tue, 27 Oct 2020 01:09:08 +0530 Subject: [PATCH 20/20] Update math/lcm_sum.cpp Co-authored-by: Ayaan Khan --- math/lcm_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index 4800ed66a..34b46020f 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -25,7 +25,7 @@ namespace math { * @param num input number * @returns int Sum of LCMs, i.e. ∑LCM(i, num) from i = 1 to num */ - uint64_t lcmSum(uint16_t num) { + uint64_t lcmSum(const uint16_t& num) { uint64_t i=0, j=0; std::vector eulerTotient(num+1);