Skip to content

Commit ca97181

Browse files
authored
Create hyperperfect.py
Return the nth K-Hyperperfect number.
1 parent 5efab0c commit ca97181

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Hyperperfect Numbers/hyperperfect.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import math
2+
3+
def divisor_function(num):
4+
i = 1
5+
s = 0
6+
while i * i <= num:
7+
if num % i == 0:
8+
if i == num/i:
9+
s += i
10+
else:
11+
s += i + num/i
12+
i += 1
13+
return int(s - num)
14+
15+
def isHyperPerfect(num):
16+
d = divisor_function(num)
17+
if d - 1 == 0:
18+
return False
19+
if (num - 1) % (d - 1) == 0:
20+
return True
21+
else:
22+
return False
23+
24+
def main():
25+
n = int(input('Enter n: '))
26+
count = -1
27+
curr = 5
28+
while count < n:
29+
curr += 1
30+
if isHyperPerfect(curr):
31+
count += 1
32+
print(curr)
33+
34+
main()

0 commit comments

Comments
 (0)