A. Divisibility
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x thata ≤ x ≤ b and x is divisible by k.

Input

The only line contains three space-separated integers ka and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Sample test(s)
input
1 1 10
output
10
input
2 -4 4
output
5

不得不说,这题的思路和上一个一样的
不妨我们考虑多点,[a,b]可以整除的个数  
a<0 b<0     (-a)/k-(-b)/k 考虑b是否整除
a<0 b=0     (-a)/k;  加0本身
a<0 b>0     (b)/k+(-a)/k 加0本身
a=0 b>0     (b)/k  加0本身
a>0 b>0     (b)/k-(a)/k  考虑a是否整除
a=0 b=0      0本身

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int main()
{
LL k,a,b;
LL ans=0;
cin>>k>>a>>b;
if(a<0&&b<0)
{
ans+=(-a)/k-(-b)/k;
if((-b)%k==0)
{
ans++;
}
}
else if(a<0&&b==0)
{
ans+=(-a)/k;
ans++;
}
else if(a<0&&b>0)
{
ans+=(b)/k+(-a)/k;
ans++;
}
else if(a==0&&b>0)
{
ans+=(b)/k;
ans++;
}
else if(a>0&&b>0)
{
ans+=(b)/k-(a)/k;
if(a%k==0)
{
ans++;
}
}
else if(a==0&&b==0)
{
ans++;
}
cout<<ans<<endl;
return 0;
}

  

Testing Round #12 A的更多相关文章

  1. Codeforces Testing Round #12 C. Subsequences 树状数组

    C. Subsequences     For the given sequence with n different elements find the number of increasing s ...

  2. Codeforces Testing Round #12 C. Subsequences 树状数组维护DP

    C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  3. Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...

  4. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  5. Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp

    题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...

  6. Testing Round #12 B

    Description A restaurant received n orders for the rental. Each rental order reserve the restaurant ...

  7. Testing Round #12 C

    Description For the given sequence with n different elements find the number of increasing subsequen ...

  8. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  9. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

随机推荐

  1. struts一些实用常量配置_2015.01.04

  2. Tomcat上的项目部署到WebLogic上の注意事项

    1.修改web.xml: <!-- <display-name>weboutweb</display-name> --> <!-- 注释掉 display-n ...

  3. 夺命雷公狗---node.js---22之项目的构建在node+express+mongo的博客项目7之数据的修改

    在修改的时候和在PHP里面修改的一样,都是需要在列表页传个id过来才可以实现修改的,如下所示: 然后在后端接收到他传过来id的同时去读取该id的所有信息: 然后就开始写post处理数据方面的问题了,如 ...

  4. SLC、MLC和TLC三者的区别

    SLC=Single-LevelCell,即1bit/cell,速度快寿命长,价格超贵(约MLC3倍以上的价格),约10万次擦写寿命 MLC=Multi-LevelCell,即2bit/cell,速度 ...

  5. 【sinatra】结合Padrino framework

    用Sinatra来做复杂的Web应用时,会出现若干个比较麻烦的点. 要手工作成一个个的应用骨架.作成test .view.public目录等等 将Sinatra DSL集中在一个类中的话,画面数量增加 ...

  6. 4项技巧使你不再为PHP中文编码苦恼

    PHP程序设计中中文编码问题曾经困扰很多人,导致这个问题的原因其实很简单,每个国家(或区域)都规定了计算机信息交换用的字符编码集,如美国的扩展 ASCII 码,中国的 GB2312-80,日本的 JI ...

  7. knockout之各种数据绑定方法:text、attr、visible、html、css、style绑定

    http://knockoutjs.com/documentation/attr-binding.html(Knockout官网文档) 1.text绑定 目的:text 绑定到DOM元素上,使得该元素 ...

  8. Android_adb详解

    adb定义:adb(android debug bridge)是android系统中的一种命令行工具,通过它可以和android设备或模拟器通信. adb工具位置: <path-to-sdk&g ...

  9. tomcat支持的websocket服务

    首发:个人博客 在tomcat7之后的版本,写个websocket服务程序非常容易——如以下代码所示,当客户端建立了一个连接并发送了一些什么内容到服务器,服务器将每隔两秒返回一个字符串“world”. ...

  10. windows prompt personalize 设置cmd提示的相关

    由于有一篇随笔种我说要引用这篇文章,所以不得已也出来了,就像你说大话『我明天去吃屎』,结果你做到了. 我这记录一下有关windows prompt这是的变量,我不知道这算不算变量,因为windows变 ...