Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
aliquot_sum.cpp File Reference

Program to return the Aliquot Sum of a number. More...

#include <cassert>
#include <iostream>
Include dependency graph for aliquot_sum.cpp:

Namespaces

namespace  math
 for IO operations
 

Functions

uint64_t math::aliquot_sum (const uint64_t num)
 to return the aliquot sum of a number
 
static void test ()
 Self-test implementations.
 
int main ()
 Main function.
 

Detailed Description

Program to return the Aliquot Sum of a number.

The Aliquot sum \(s(n)\) of a non-negative integer n is the sum of all proper divisors of n, that is, all the divisors of n, other than itself.

Formula:

\[ s(n) = \sum_{d|n, d\neq n}d. \]

For example; \(s(18) = 1 + 2 + 3 + 6 + 9 = 21 \)

Author
SpiderMath

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit
73 {
74 test(); // run the self-test implementations
75 return 0;
76}
static void test()
Self-test implementations.
Definition aliquot_sum.cpp:56
Here is the call graph for this function:

◆ test()

static void test ( )
static

Self-test implementations.

Returns
void
56 {
57 // Aliquot sum of 10 is 1 + 2 + 5 = 8
58 assert(math::aliquot_sum(10) == 8);
59 // Aliquot sum of 15 is 1 + 3 + 5 = 9
60 assert(math::aliquot_sum(15) == 9);
61 // Aliquot sum of 1 is 0
62 assert(math::aliquot_sum(1) == 0);
63 // Aliquot sum of 97 is 1 (the aliquot sum of a prime number is 1)
64 assert(math::aliquot_sum(97) == 1);
65
66 std::cout << "All the tests have successfully passed!\n";
67}
uint64_t aliquot_sum(const uint64_t num)
to return the aliquot sum of a number
Definition aliquot_sum.cpp:35
Here is the call graph for this function: