Repository navigation
4. Arithmetic
The namespace Arithmetic contains the following functions
Splits the intger n into digits and returns it in the form of an array. End is signaled by -1
Parameters:
int64_t n - The integer n to be split
Return value:
int* - An array containing the digits if n
Sample usage (after including header file):
int* digits = Arithmetic::digitizeArray(1234);
//returns array {1, 2, 3, 4, -1}
Returns a bool value saying if the number n is a palindrome or not when represented in base base
Parameters:
int64_t number - The integer n to be determined if palindrome or not
int base - The base in which the number n is to represented
Return value:
bool - 1 (true) if n is palindrome in base base. 0 (false) otherwise.
Sample usage (after including header file):
bool a = Arithmetic::isPalindrome(1234321, 10); //returns true
bool b = Arithmetic::isPalindrome(3, 2); //returns true - 3 is 11 in base 2
Returns bool depending on whether the number n is pandigtial or not. A pandigital number has digits from 1 to n exactly once. Or it could be from 0 to n.
Parameters:
int64_t n - The integer n to determined if pandigtial or not
bool zero - Set to true if 0 should be counted. Set to false if looking for only from 1 to n.
Return value:
bool - true if pandigital. false otherwise.
Sample usage (after including header file):
bool a = Arithmetic::isPandigital(1234, false); //returns true
bool b = Arithmetic::isPandigital(1023, true); //returns true
bool c = Arithmetic::isPandigitial(1023, false); //returns false
bool c = Arithmetic::isPandigitial(1234, true); //returns false
Returns a bool determining whether the number is a prefect square or not.
Parameters:
int64_t n - The input number
Return value:
bool - true if n is a perfect square. false otherwise.
Sample usage (after including header file):
bool a = Arithmetic::isPerfectSquare(25); //returns true
bool b = Arithmetic::isPerfectSquare(50); //returns false
Concatenates two integers a and b in that order.
Parameters:
int64_t a - The preceding number
int64_t b - The following number
Return value:
int64_t - The integer derived by concatenating a and b
Sample usage (after including header file):
int64_t x = Arithmetic::concatInt(45, 33); // x = 4533
Finds a list of all divisors of the number
Parameters:
int64_t n - The number
bool proper - Set to true if only proper divisors are needed
Return value:
int64_t* - An array of all divisors. End is signalled by -1
Sample usage (after including header file):
int64_t* x = Arithmetic::divisors(45, false); // {1, 3, 5, 9, 45, -1}