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. 输入和输出的总结(c语言)

    c语言中有多种的输入和输出方式,下面就简单总结一下: 一.输入的三种方式 (1)scanf scanf 函数可以在变量中使用,也可以在数组中使用,当然指针上也能用到,是一个很好的输入函数.scanf是 ...

  2. [转] FastJson---高性能JSON开发包

    原文地址: FastJson---高性能JSON开发包 Fastjson介绍 Fastjson是一个Java语言编写的JSON处理器,由阿里巴巴公司开发.1.遵循http://json.org标准,为 ...

  3. having 子句

    having 子句-->过滤分组,用于限制分组显示结果 a.行已经被分组 b.使用了分组函数 c.满足having子句中条件的分组将被重写

  4. CCF真题之窗口

    201403-2 问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域.窗口的边界上的点也属于该窗口.窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示 ...

  5. ThinkPHP 中实现 Rewrite 模式

    ThinkPHP中默认的URL地址是形如这样的:http://localhost/Myapp/index.php/Index/index/ Myapp是我的项目文件名,默认的访问地址是上面这样的.为了 ...

  6. Socket get http request

    package wuyubao.firstsample; import java.io.BufferedReader; import java.io.IOException; import java. ...

  7. 夺命雷公狗---DEDECMS----8dedecms干掉首页和-文档页-栏目页的页面的广告

    我们首先来将首页生成静态页面,如下图所示: 成功后,如下显示: 如果成功后则在文件夹下多了一个index.html的文件.. 我们的首页静态页面是通过模版文件生成,所以我们只需要把模版文件的广告标签删 ...

  8. 对Alexia(minmin)网友代码的评论及对“求比指定数大且最小的‘不重复数’问题”代码的改进

    应Alexia(minmin)网友之邀,到她的博客上看了一下她的关于“求比指定数大且最小的‘不重复数’问题”的代码(百度2014研发类校园招聘笔试题解答),并在评论中粗略地发表了点意见. 由于感觉有些 ...

  9. OpenStack 服务状态检查

    openstack服务不正常 使用命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [root@node-5 TimaIaas]# nova- ...

  10. Java简单数据类型转换

      1. Integer<---String   (1) Integer x = new Integer(Integer.parseInt(String)); 2. Integer<--- ...