Skip to content

Commit 37f74c6

Browse files
authored
Add files via upload
1 parent 86a1306 commit 37f74c6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Arrays/Divisor_Sum.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
Aim: Calculate the sum of all the divisors of the entered number and display it.
3+
4+
'''
5+
6+
# function to find out all divisors and add them up
7+
def divisorSum(n):
8+
temp = []
9+
for i in range(1, n+1):
10+
# condition for finding factors
11+
if n%i == 0:
12+
temp.append(i)
13+
# adding all divisors
14+
return sum(temp)
15+
16+
# getting the input
17+
n = int(input())
18+
# printing the result
19+
print(divisorSum(n))
20+
21+
'''
22+
23+
COMPLEXITY:
24+
25+
Time Complexity -> O(N)
26+
Space Complexity -> O(1)
27+
28+
Sample Input:
29+
6
30+
Sample Output:
31+
12
32+
33+
Explaination:
34+
Divisors/Factors of 6 are --> 1,2,3 and 6.
35+
Adding them up --> 1+2+3+6 = 12.
36+
37+
'''

0 commit comments

Comments
 (0)