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)
 
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. For example, the Aliquot sum of 18 = 1 + 2 + 3 + 6 + 9 = 21

Author
SpiderMath

Function Documentation

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
64 {
65 test(); // run the self-test implementations
66
67 return 0;
68}
static void test()
Self-test implementations.
Definition: aliquot_sum.cpp:47
Here is the call graph for this function:

◆ test()

static void test ( )
static

Self-test implementations.

Returns
void
47 {
48 // Aliquot sum of 10 is 1 + 2 + 5 = 8
49 assert(math::aliquot_sum(10) == 8);
50 // Aliquot sum of 15 is 1 + 3 + 5 = 9
51 assert(math::aliquot_sum(15) == 9);
52 // Aliquot sum of 1 is 0
53 assert(math::aliquot_sum(1) == 0);
54 // Aliquot sum of 97 is 1 (the aliquot sum of a prime number is 1)
55 assert(math::aliquot_sum(97) == 1);
56
57 std::cout << "All the tests have successfully passed!\n";
58}
uint64_t aliquot_sum(const uint64_t num)
Definition: aliquot_sum.cpp:26
Here is the call graph for this function: