[Codility] CountDiv



50% (Performance 0)


def solution(A, B, K):
    num = [i for i in range(A,B+1)]

    num = list(filter(lambda x : x%K==0 , num))

    return len(num)
    

def solution(A, B, K):
    count = 0
    for i in range(A, B+1):
        if i % K == 0:
            count +=1
    return count
    

75%


def solution(A, B, K):
    return (B-A)//K + int(A%K == 0) 

100%



ドアを使わずに数学で答えられるなら、できるだけその方法を探してください.
def solution(A, B, K):
    return B//K - (A-1)//K