-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
52 lines (44 loc) · 823 Bytes
/
Copy pathhelpers.py
File metadata and controls
52 lines (44 loc) · 823 Bytes
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
import math
class Helpers:
def __init__(self):
pass
@staticmethod
def pr(r):
print("result is: " + str(r))
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2 or n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
check = range(2, int(n ** .5) + 1)
for i in check:
if n % i == 0:
return False
return True
@staticmethod
def number_of_divisors(n):
"""
find the number of divisors for supplied n
:param n: int
:return: int
"""
result = 0
sqrt = int(math.sqrt(n))
for i in range(1, sqrt + 1):
if n % i == 0:
result += 2
# if perfect square root, don't count twice
if n == sqrt * sqrt:
result -= 1
return result
@staticmethod
def gcd(a, b):
if b == 0:
return a
else:
return Helpers.gcd(b, a % b)