forked from Mickey0521/Codility-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountFactors.py
More file actions
31 lines (23 loc) · 715 Bytes
/
CountFactors.py
File metadata and controls
31 lines (23 loc) · 715 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
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(N):
# write your code in Python 3.6
my_dictionary = {}
# be careful about the range
# O(n)
'''
for n in range( 1, N+1 ):
if N % n == 0:
my_dictionary[n] = True
'''
# O( log(n) )
# be careful: we need to check 'math.sqrt(N)+1'
for n in range( 1, int( math.sqrt(N) ) +1 ):
if N % n ==0:
my_dictionary[n] = True
another_factor = int( N/n )
my_dictionary[another_factor] = True
# print(my_dictionary)
num_factors = len( my_dictionary )
return num_factors