Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Problem 23 solution - optimization using look-up array More...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Functions | |
char | get_perfect_number (unsigned long N) |
char | is_abundant (unsigned long N) |
Is the given number an abundant number (1) or not (0) | |
unsigned long | get_next_abundant (unsigned long N) |
Find the next abundant number after N and not including N. | |
char | is_sum_of_abundant (unsigned long N) |
check if a given number can be represented as a sum of two abundant numbers. | |
int | main (int argc, char **argv) |
Main function. | |
Variables | |
char * | abundant_flags = NULL |
This is the global array to be used to store a flag to identify if a particular number is abundant (1) or not (0). | |
Problem 23 solution - optimization using look-up array
Optimization applied - compute & store abundant numbers once into a look-up array.
unsigned long get_next_abundant | ( | unsigned long | N | ) |
Find the next abundant number after N and not including N.
char get_perfect_number | ( | unsigned long | N | ) |
char is_abundant | ( | unsigned long | N | ) |
Is the given number an abundant number (1) or not (0)
char is_sum_of_abundant | ( | unsigned long | N | ) |
check if a given number can be represented as a sum of two abundant numbers.
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function.
char* abundant_flags = NULL |
This is the global array to be used to store a flag to identify if a particular number is abundant (1) or not (0).
Using a whole byte to store a binary info would be redundant. We will use each byte to represent 8 numbers by relying on bits. This saves memory required by 1/8