Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
sol1.c File Reference

Problem 23 solution More...

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Include dependency graph for sol1.c:

Functions

char get_perfect_number (unsigned long N)
 Returns: -1 if N is deficient 1 if N is abundant 0 if N is perfect.
 
unsigned long 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. More...
 
int main (int argc, char **argv)
 Main function.
 

Detailed Description

Problem 23 solution

Author
Krishna Vedala

Function Documentation

◆ is_sum_of_abundant()

char is_sum_of_abundant ( unsigned long  N)

check if a given number can be represented as a sum of two abundant numbers.

Returns
1 - if yes
0 - if not
72 {
73  /* optimized logic:
74  * i + j = N where both i and j should be abundant
75  * hence we can simply check for j = N - i as we loop through i
76  */
77  for (unsigned long i = get_next_abundant(1); i <= (N >> 1);
78  i = get_next_abundant(i))
79  {
80  if (is_abundant(N - i))
81  {
82 #ifdef DEBUG
83  printf("\t%4lu + %4lu = %4lu\n", i, N - i, N);
84 #endif
85  return 1;
86  }
87  }
88  return 0;
89 }
Here is the call graph for this function:
get_next_abundant
unsigned long get_next_abundant(unsigned long N)
Find the next abundant number after N and not including N.
Definition: sol1.c:55
is_abundant
unsigned long is_abundant(unsigned long N)
Is the given number an abundant number (1) or not (0)
Definition: sol1.c:47