Factors of a number (#1493) · coderjack/algorithms-in-python@53ff735 · GitHub
Skip to content

Commit 53ff735

Browse files
himanshujaindevcclauss
authored andcommitted
Factors of a number (TheAlgorithms#1493)
* Factors of a number * Update factors.py * Fix mypy issue in basic_maths.py * Fix mypy error in perceptron.py * def primes(max: int) -> List[int]: * Update binomial_heap.py * Add a space * Remove a space * Add a space
1 parent f8e97aa commit 53ff735

5 files changed

Lines changed: 109 additions & 99 deletions

File tree

data_structures/heap/binomial_heap.py

Lines changed: 86 additions & 91 deletions

maths/basic_maths.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ def euler_phi(n: int) -> int:
6767
>>> euler_phi(100)
6868
40
6969
"""
70-
l = prime_factors(n)
71-
l = set(l)
7270
s = n
73-
for x in l:
71+
for x in set(prime_factors(n)):
7472
s *= (x - 1) / x
7573
return int(s)
7674

maths/factors.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def factors_of_a_number(num: int) -> list:
2+
"""
3+
>>> factors_of_a_number(1)
4+
[1]
5+
>>> factors_of_a_number(5)
6+
[1, 5]
7+
>>> factors_of_a_number(24)
8+
[1, 2, 3, 4, 6, 8, 12, 24]
9+
>>> factors_of_a_number(-24)
10+
[]
11+
"""
12+
return [i for i in range(1, num + 1) if num % i == 0]
13+
14+
15+
if __name__ == "__main__":
16+
num = int(input("Enter a number to find its factors: "))
17+
factors = factors_of_a_number(num)
18+
print(f"{num} has {len(factors)} factors: {', '.join(str(f) for f in factors)}")

maths/prime_numbers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
"""Prime numbers calculation."""
1+
from typing import List
22

33

4-
def primes(max: int) -> int:
4+
def primes(max: int) -> List[int]:
55
"""
6-
Return a list of all primes up to max.
6+
Return a list of all primes numbers up to max.
77
>>> primes(10)
88
[2, 3, 5, 7]
99
>>> primes(11)

neural_network/perceptron.py

Lines changed: 1 addition & 2 deletions

0 commit comments

Comments
 (0)