We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 86a1306 commit 37f74c6Copy full SHA for 37f74c6
Arrays/Divisor_Sum.py
@@ -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