본문 바로가기
Problem Solving/Codility

[Python] 5.1. CountDiv

by 부르르 2021. 3. 15.

https://app.codility.com/programmers/lessons/5-prefix_sums/

 

5. Prefix Sums lesson - Learn to Code - Codility

Compute number of integers divisible by k in range [a..b].

app.codility.com


Task Score: 100%

Correctness: 100%

Performance:100%

시간복잡도: O(1)

def solution(A, B, K):

    answer = 0

    if A == 0:
        answer += 1

    if A <= K:
        A = K
    else:
        if A % K == 0:
            pass
        else:
            A += K - ( A % K )
    
    answer += ((B-A)//K)+1

    return answer
728x90
반응형

'Problem Solving > Codility' 카테고리의 다른 글

[Python] 5.3. MinAvgTwoSlice  (0) 2021.03.18
[Python] 5.2. GenomicRangeQuery  (0) 2021.03.16
[Python] 4.4. PermCheck  (0) 2021.03.15
[Python] 4.3. MissingInteger  (0) 2021.03.15
[Python] 4.2. MaxCounters  (0) 2021.03.14

댓글