메모장 입니다2
codility] CountDiv 본문
1. 설명
that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.:
{ i : A ≤ i ≤ B, i mod K = 0 }
For example, for A = 6, B = 11 and K = 2, your function should return 3, because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 and 10.
> 배수의 수
>시간 복잡도 O(1)
2.소스
// you can use includes, for example: // #include <algorithm> // you can write to stdout for debugging purposes, e.g. // cout << "this is a debug message" << endl; int solution(int A, int B, int K) { // write your code in C++14 (g++ 6.2.0) int ret =0; int remain = (B-A+1)%K; for(int i=A; i<A+remain; i++) { if(i%K ==0) { ret++; break; } } ret += (B-A+1)/K; return ret; }
https://codility.com/demo/results/trainingXVANQD-AHF/
'Study > Programming' 카테고리의 다른 글
codility] Distinct (0) | 2017.11.10 |
---|---|
codility] MinAvgTwoSlice (0) | 2017.11.07 |
codility] MissingInteger (0) | 2017.11.02 |
codility] PermMissingElem (0) | 2017.11.01 |
codility] TapeEquilibrium (0) | 2017.11.01 |