Skip to content

Commit adc792e

Browse files
authored
Merge pull request prabhupant#355 from shotanozadze/master
division factors
2 parents 06a639c + 716a4ac commit adc792e

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
questions_to_do.txt
2+
.DS_Store

algorithms/math/divisors.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import math
2+
3+
class divisors:
4+
5+
def findAllDivisors(self, n):
6+
result = list()
7+
8+
for i in range(1, n+1):
9+
if (n%i == 0):
10+
result.append(i)
11+
12+
return result
13+
14+
def divisorsCount(self, n):
15+
divs = self.findAllDivisors(n)
16+
return len(divs)
17+
18+
def oddFactors(self, n):
19+
result = list()
20+
21+
for i in range(1, n+1):
22+
if (n%i == 0 and i%2==1):
23+
result.append(i)
24+
25+
return result
26+
27+
def oddFactorsSum(self, n):
28+
divs = self.evenFactors(n)
29+
return sum(divs)
30+
31+
def evenFactors(self, n):
32+
result = list()
33+
34+
for i in range(1, n+1):
35+
if (n%i == 0 and i%2==0):
36+
result.append(i)
37+
38+
return result
39+
40+
def evenFactorsSum(self, n):
41+
divs = self.evenFactors(n)
42+
return sum(divs)
43+
44+
def primeFactors(self, n):
45+
result = list()
46+
47+
while n % 2 == 0:
48+
result.append(2)
49+
n = n / 2
50+
51+
for i in range(3,int(math.sqrt(n))+1,2):
52+
while n % i== 0:
53+
result.append(i)
54+
n = n / i
55+
56+
if n > 2:
57+
result.append(n)
58+
59+
return result
60+
61+
def primeFactorsSum(self, n):
62+
divs = self.primeFactors(n)
63+
return sum(divs)

0 commit comments

Comments
 (0)