https://codility.com/demo/take-sample-test/count_div

此题比较简单,是在O(1)时间里求区间[A,B]里面能被K整除的数字,那么就计算一下就能得到。

int solution(int A, int B, int K) {
// write your code in C++11
int diff = (B-A+1);
int result = diff / K;
for (int i = A + result * K; i <= B; i++)
{
if (i % K == 0)
result++;
}
return result;
}

  

[codility]CountDiv的更多相关文章

  1. Codility NumberSolitaire Solution

    1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...

  2. codility flags solution

    How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...

  3. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  4. *[codility]Peaks

    https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...

  5. *[codility]Country network

    https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...

  6. *[codility]AscendingPaths

    https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...

  7. *[codility]MaxDoubleSliceSum

    https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...

  8. *[codility]Fish

    https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...

  9. *[codility]CartesianSequence

    https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...

随机推荐

  1. php 获取链接参数

    private function getQuerystr($url,$key){        $res = '';        $a = strpos($url,'?');        if($ ...

  2. 51nod 1021 石头归并

    1021 石子归并 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 N堆石子摆成一条线.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合 ...

  3. phpExcel导出excel的类,每步都有说明

    require_once WEB_PATH . '/lib/PHPExcel/PHPExcel.php'; require_once WEB_PATH . '/lib/PHPExcel/PHPExce ...

  4. 为Eclipse设置背景色

    1:打开Eclipse,在菜单栏找到Help—>Install new software.. 2:在打开的Work with中输入: Update Site - http://eclipse-c ...

  5. How to disable Passwords must meet complexity requirements[windows 7]

    The Password complexity is a Local Policy setting named "Passwords must meet complexity require ...

  6. 查看SQL Server 备份信息

    RESTORE HEADERONLY FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008\MSSQL\Back ...

  7. redis使用场景

    Redis应用场景   Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作 ...

  8. Pomodairo,番茄工作法-应用篇

    传统:              选择一个待完成的任务              将番茄时间设为适合自己的固定时间              专注工作,中途不允许做任何与该任务无关的事,直到番茄时钟响 ...

  9. SOLVED: GATT callback fails to register

    I finally figured this problem out. The device I am using is a Samsung Galaxy S4 and the actual prob ...

  10. Interview-Harry Potter walk through matrix.

    假设你是harry potter,在grid的左上角,你现在要走到右下角,grid中有正数也有负数,遇到正数表示你的strength增加那么多,遇到负数表示strength减少那么多,在任何时刻如果你 ...