forked from Mickey0521/Codility-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountDiv_v2.py
More file actions
30 lines (21 loc) · 778 Bytes
/
CountDiv_v2.py
File metadata and controls
30 lines (21 loc) · 778 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
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, K):
# write your code in Python 3.6
# need to achieve low complexity O(1)
# using math equation (low complexity)
# number of divisible values smaller than B
num_B = B // K
# note: take "Math.floor" which is the basic number
# number of divisible values smaller than A
num_A = A // K
# note: take "Math.floor" which is the basic number
# number of divisible numbers
num_divisible = num_B - num_A
# note: plus one (if A % K == 0)
# because "A" is also divisble
plus = 0
if A % K ==0:
plus =1
num_divisible = num_divisible + plus
return num_divisible