forked from seeditsolution/pythonprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbundantNum
More file actions
47 lines (38 loc) · 852 Bytes
/
AbundantNum
File metadata and controls
47 lines (38 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import math
# Function to calculate sum of divisors
def getSum(n) :
sum = 0
# Note that this loop runs till square root
# of n
i = 1
while i <= (math.sqrt(n)) :
if n%i == 0 :
# If divisors are equal,take only one
# of them
if n/i == i :
sum = sum + i
else : # Otherwise take both
sum = sum + i
sum = sum + (n / i )
i = i + 1
# calculate sum of all proper divisors only
sum = sum - n
return sum
# Function to check Abundant Number
def checkAbundant(n) :
# Return true if sum of divisors is greater
# than n.
if (getSum(n) > n) :
return 1
else :
return 0
# Driver program to test above function */
if(checkAbundant(12) == 1) :
print "YES"
else :
print "NO"
if(checkAbundant(15) == 1) :
print "YES"
else :
print "NO"
# This code is contributed by Nikita Tiwari.