package com.code;

public class Test05_1 {
public static int solution(int A, int B, int K) { // handle 6,8,7 condition
// handle 6,11,2 condition
// handle 7,12,3 condition
if(A%K==0){
return (B-A)/K + 1;
}else{
int start = A+(K-A%K);
if(start>B){ // handle 7,8,9 condition
return 0;
}else{
return (B-start)/K+1;
}
} }
public static void main(String[] args) { System.out.println(solution(6, 11, 2));
System.out.println(solution(6, 8, 7));
System.out.println(solution(5, 5, 3));
System.out.println(solution(6, 7, 8));
System.out.println(solution(0, 0, 11)); }
} /**
1. CountDiv 数数有几个
Compute number of integers divisible by k in range [a..b]. Write a function: class Solution { public int solution(int A, int B, int K); } 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. Assume that: A and B are integers within the range [0..2,000,000,000];
K is an integer within the range [1..2,000,000,000];
A ≤ B.
Complexity: expected worst-case time complexity is O(1);
expected worst-case space complexity is O(1). */

1. CountDiv 数数有几个 Compute number of integers divisible by k in range [a..b].的更多相关文章

  1. 【BZOJ】【3530】【SDOI2014】数数

    AC自动机/数位DP orz zyf 好题啊= =同时加深了我对AC自动机(这个应该可以叫Trie图了吧……出边补全!)和数位DP的理解……不过不能自己写出来还真是弱…… /************* ...

  2. BZOJ3530: [Sdoi2014]数数

    3530: [Sdoi2014]数数 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 322  Solved: 188[Submit][Status] ...

  3. 【HDU3530】 [Sdoi2014]数数 (AC自动机+数位DP)

    3530: [Sdoi2014]数数 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 682  Solved: 364 Description 我们称一 ...

  4. COJ 0036 数数happy有多少个?

    数数happy有多少个? 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 图图是个爱动脑子.观察能力很强的好学生.近期他正学英语 ...

  5. BZOJ 3530: [Sdoi2014]数数 [AC自动机 数位DP]

    3530: [Sdoi2014]数数 题意:\(\le N\)的不含模式串的数字有多少个,\(n=|N| \le 1200\) 考虑数位DP 对于长度\(\le n\)的,普通套路DP\(g[i][j ...

  6. 【BZOJ3530】数数(AC自动机,动态规划)

    [BZOJ3530]数数(AC自动机,动态规划) 题面 BZOJ 题解 很套路的\(AC\)自动机+\(DP\) 首先,如果长度小于\(N\) 就不存在任何限制 直接大力\(DP\) 然后强制限制不能 ...

  7. 2019.03.28 bzoj3326: [Scoi2013]数数(数位dp)

    传送门 题意: 一个人数数,规则如下: 确定数数的进制B 确定一个数数的区间[L, R] 对于[L, R] 间的每一个数,把该数视为一个字符串,列出该字符串的所有连续子串对应的B进制数的值. 对所有列 ...

  8. 「SDOI2014」数数 解题报告

    「SDOI2014」数数 题目描述 我们称一个正整数 \(N\) 是幸运数,当且仅当它的十进制表示中不包含数字串集合 \(S\) 中任意一个元素作为其子串. 例如当 \(S=(\)22, 333, 0 ...

  9. 洛谷:P3281 [SCOI2013]数数 (优秀的解法)

    刷了这么久的数位 dp ,照样被这题虐,还从早上虐到晚上,对自己无语...(机房里又是只有我一个人,寂寞.) 题目:洛谷P3281 [SCOI2013]数数 题目描述 Fish 是一条生活在海里的鱼, ...

随机推荐

  1. Mybatis的Dao向mapper传多个参数(三种解决方案)转自《super超人》

    第一种方案 : DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id=" ...

  2. FCC 基础JavaScript 练习1

    1.JavaScript中的注释方式有以下两种 // This is an in-line comment. /* This is a multi-line comment */ 2.avaScrip ...

  3. opencv3.31+vs2015终于配置成功了

    风萧萧兮易水寒, 熬了几个夜晚,终于把opencv配好了, 来图一 唉试了很多方法,终于成功. 教程和资料会发在个人网站里. 测试 代码 #include <iostream> #incl ...

  4. Android 知识Tips

    有一些Android很小的知识点,不值得单独写出来做为一篇博客.都在这个博客里面进行总结 1.ImageButton控件,中间图片的放置效果可以用scaleType来设置,如下: <ImageB ...

  5. Codeforces_768_D_(概率dp)

    D. Jon and Orbs time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. swift extension 的最终目的是结合

    与数据结合:对数据进行操作: 与行为结合:使用原有行为生成更便捷的行为: 与协议结合:实现协议: 与类型结合:对类型数据进行操作,添加新的行为: 与关联类型.泛型结合:对类型做出限定.

  7. #NOIP前数学知识总结

    我好菜啊…… 欧拉函数 欧拉函数φ(n),是小于n且和n互质的正整数(包括1)的个数. 性质: 1.对于质数n: φ(n)=n-1 2..对于n=pk φ(n)=(p-1)*pk-1 3.积性函数的性 ...

  8. MxCAD5.2 20181022更新

    下载地址: http://www.mxdraw.com/ndetail_10108.html 1. 开放VIP功能,无需购买即可使用 2. 修正一些图纸打开和保存出错的问题 3. 修改填充命令,对某些 ...

  9. IDEA SpringBoot项目连接数据库报Acess denied错误解决方法

    详见:https://blog.csdn.net/qq_36324464/article/details/79534605

  10. input password密码验证跳转页面

    代码如下: 查询密码 <input type="password" id="pwd" /> 页面如下: 密码校验成功后跳转页面: window.lo ...