-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathPrimaryPseudoperfect.py
45 lines (37 loc) · 1016 Bytes
/
PrimaryPseudoperfect.py
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
import math
# Since dealing with floating points, need a threshold
thresh = 0.0000001
def primeFactors(n):
divisors = set()
# Continuously divide by 2 until odd
while n % 2 == 0:
divisors.add(2)
n = n / 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for i in range(3,int(math.sqrt(n))+1,2):
# Continuously divide by i until indivisible by i
while n % i== 0:
divisors.add(i)
n = n / i
# Condition if n is a prime
# number greater than 2
if n > 2:
divisors.add(n)
return divisors
def isPrimaryPseudoperfect(num):
prime_factors = primeFactors(num)
s = 0
for p in prime_factors:
s += 1/p
return abs(((1/num) + s) - 1) <= thresh
def main():
n = int(input('Enter n: '))
count = -1
curr = 1
while count < n:
curr += 1
if isPrimaryPseudoperfect(curr):
count += 1
print(curr)
main()