If the sum of all the valid divisors of a given number, denoted as sum(n), surpasses the numerical value of the number n, it is classified as abundant. Abundance is calculated as the discrepancy between these two quantities.
In mathematical terms, a number is considered abundant if the following condition holds:
sum(n)> n
abundance = sum(n) - n
sum(n): aliquot sum - The sum of all proper divisors of n
In this section, we aim to establish if a provided number, denoted as n, qualifies as an abundant number.
12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, and 66 represent the initial abundant numbers in the sequence.
Working:-
For user input, the num
- Find all proper divisors of num
- Calculate the sum of these divisors
- If sum > num: Abundant number
- Else, not an Abundant number
Method 1
For user input, the num
- Initialize sum = 0
- Run a loop in the iteration of (i)
- For each, i check if it is a divisor of num (num % i == 0)
- If yes, add to the sum
- Compare sum and num. If sum > num , its an abundant number.
Program:
Let's consider an example to demonstrate the prolific number in C programming.
#include <stdio.h>
int main ()
{
int num = 18, sum = 0;
for(int i = 1; i < num; i++)
{
if(num % i == 0)
sum = sum + i;
}
if(sum > num){
printf("%d is an Abundant Number\n",num);
printf("Num: %d\nSum: %d\nAbundance: %d", num, sum, (sum-num));
} else
printf("%d is not a Abundant Number",num);
}
Output:
[Program Output]
Complexity Analysis:
Time complexity: O(N)
Space complexity: O(1)
Method 2:[using observations]
- This method uses observations that all factors come in pairs.
- All Factors come in pairs.
- For n = a * b (For each a, there exists a unique b)
Example: 100 (1,100), (2, 50), (4, 25), (5, 20), and (10, 100)
Shorten the loop
We can shorten the loop running between [1, num] to [1, √num]
Since we will find all pairs before √num (n = sqrt(n) * sqrt(n))
Program:
Let's consider another instance to demonstrate the plentiful number concept in C programming.
#include <stdio.h>
#include <math.h>
int getSum(int num){
int sum = 0;
for(int i = 1; i < sqrt(num); i++)
{
if (num % i == 0)
{
// For num : (1, num) will always be a pair of divisor
// acc to def., we must ignore adding num itself as the divisor
//When calculating for an abundant number
if(i == 1)
sum = sum + i;
// Example For 100 (10,10) will be one of the pair
// But, we should add value 10 to the sum just once
else if(i == num/i)
sum = sum + i;
//Add both pairs as divisors
// For any divisor i, num/i will also be a divisor
else
sum = sum + i + num/i;
}
}
return sum;
}
//main Program
int main()
{
int num=10;
int sum = getSum(num);
if(sum > num)
{
printf("%d is an Abundant Number\n",num);
printf("Num: %d\nSum: %d\nAbundance: %d", num, sum, (sum-num));
}
else
printf("%d is not a Abundant Number",num);
}
Output: