-
Notifications
You must be signed in to change notification settings - Fork 619
/
Copy pathdivisors.py
63 lines (44 loc) · 1.32 KB
/
divisors.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import math
class divisors:
def findAllDivisors(self, n):
result = list()
for i in range(1, n+1):
if (n%i == 0):
result.append(i)
return result
def divisorsCount(self, n):
divs = self.findAllDivisors(n)
return len(divs)
def oddFactors(self, n):
result = list()
for i in range(1, n+1):
if (n%i == 0 and i%2==1):
result.append(i)
return result
def oddFactorsSum(self, n):
divs = self.evenFactors(n)
return sum(divs)
def evenFactors(self, n):
result = list()
for i in range(1, n+1):
if (n%i == 0 and i%2==0):
result.append(i)
return result
def evenFactorsSum(self, n):
divs = self.evenFactors(n)
return sum(divs)
def primeFactors(self, n):
result = list()
while n % 2 == 0:
result.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
result.append(i)
n = n / i
if n > 2:
result.append(n)
return result
def primeFactorsSum(self, n):
divs = self.primeFactors(n)
return sum(divs)