Skip to content

Commit 9b7e39c

Browse files
committed
🐛 Sum of Proper Divisor's Python & C++ Code Corner Case Fixed
1 parent 6200454 commit 9b7e39c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Sum of Proper Divisors/SumOfProperDivisors.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ public static void main(String[] args) {
99
}
1010

1111
private static int seq(int n) {
12+
if (n == 1) {
13+
return 0;
14+
}
1215
int res = 0;
1316
int i = 2;
14-
while(i <= Math.sqrt(n)){
15-
if(n % i == 0){
16-
res = (i == (n/i)) ? res+i : res + (i + (n/i));
17+
while (i <= Math.sqrt(n)) {
18+
if (n % i == 0) {
19+
res = (i == (n / i)) ? res + i : res + (i + (n / i));
1720
}
1821
i += 1;
1922
}
20-
return (res+1);
23+
return (res + 1);
2124
}
2225
}

Sum of Proper Divisors/SumOfProperDivisors.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import math
22

33
def divsum(n):
4+
if n == 1:
5+
return 0
46
res = 0
57
i = 2
68
while( i <= math.sqrt(n)):

0 commit comments

Comments
 (0)