Divisibility
2016-07-21 20:07
330 查看
A - DivisibilityTime Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionFind the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integervalues x that a ≤ x ≤ b and x is divisibleby k.InputThe only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).OutputPrint the required number.Sample InputInput
1 1 10Output
10Input
2 -4 4Output
5AC代码:
#include<stdio.h>int main(){__int64 k,a,b;while(scanf("%I64d%I64d%I64d",&k,&a,&b)!=EOF){if(a>0&&b>0)printf("%I64d\n",b/k-(a-1)/k);if(a<=0&&b>=0)printf("%I64d\n",(b/k-a/k)+1);if(a<0&&b<0)printf("%I64d\n",(b+1)/k-a/k);}return 0;}
相关文章推荐
- 机器学习系列(1)_逻辑回归初步
- Java加密解密算法-MD5加密解密
- 【离散数学】偏序关系与全序关系的区别、解释(偏序集合、全序集合)
- 【离散数学】么元、左么元和右么元的定义(幺元、单位元)
- nagios系列(二)之nagios客户端的安装及配置
- Ceph cache pool tiering: a scalable and distributed cache
- PHP 数据库mysql链接,以及读取数据内容方式详解
- PHP使用3DES算法加密解密字符串
- HDU 5738 Eureka (from: 2016 Multi-University Training Contest 2)
- 【操作系统】进程的异步性
- HDU 5744 Keep On Movin
- 为何银行愿为收购supercell做无权追索融资?
- 栈的顺序存储结构和链式存储结构
- 4000 图片水印的添加
- cocos2dx-3.0(24) onEnter()、onExit()、init()等场景生命周期函数介绍
- Java 多线程:ThreadLocal关键字
- IKBC poker 2更换WIN键与ALT键(option键与command键)
- nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException
- Wicket + Spring integration example
- hdu 2000