Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abundant Number #835

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Python/AbundantNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#Python program to check if a number is Abundant or not

def is_abundant(n):
s=0
for i in range(1,n): # This for loop calculates the sum of the divisors of a number
if n%i==0:
s = s + i

a = s-n #Calculates the difference between the sum of the divisors and the given number

if s > n:
print(n,"is an Abundant Number and the Abundance is",a)
else :
print(n,"is not an Abundant Number")

#User Input:
print("Enter the number to check:")
n = int(input())

is_abundant(n)


'''
Explanation:
A number is said to be abundant if the sum of the divisors of the
number is greater than the number itself. And the differnce between these two
values is called the abundance of an abundant number.

Examples of Abundant Numbers:
->12:
Divisors of 12: 1,2,3,4,6
Sum of divisors: 16
Abundance: 16-12 = 4

->18:
Divisors of 18: 1,2,3,6,9
Sum of divisors: 21
Abundance: 21-18 = 3

Sample Input:
Enter the Number to check:
12

Sample Output:
12 is an Abundant Number and the Abundance is 4

Time Complexity : O(n)
Space Complexity : O(1)

'''
2 changes: 2 additions & 0 deletions Python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Format: -[Program name](name of the file)

-[0/1 Knapsack Problem using Dynamic Programming approach](Knapsack_DP.py)

-[Abundant Number](AbundantNumber.py)

-[Anagrams](anagrams.py)

-[Arithmetic Progression](arithmetic.py)
Expand Down