알고리즘

[codility] 풀어보기 - CountDiv

Dohoon 2017. 10. 24. 15:58

Lesson 5-2  - CountDiv

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

시간 복잡도 : O(1)

정답 코드 :


1
2
3
4
5
6
7
8
9
10
11
int solution(int A, int B, int K) {
 
    double a = A;
    double b = B;
     
    int ret =  floor(b/K) - floor((a - 1)/K); 
     
    return  ret;
     
}
 
cs

출처 : http://ccomsi.tistory.com/56


이번엔 수학 이론을 알아야 가능 했던 문제 인 듯...
수포자는 ㅠㅠ

수학 이론은
여기에서 확인 가능