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. nyist 596 谁是最好的Coder

    http://acm.nyist.net/JudgeOnline/problem.php?pid=596 谁是最好的Coder 时间限制:1000 ms  |  内存限制:65535 KB 难度:0 ...

  2. php 警告

    php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...

  3. 软件需求分析之NABCD模型

    软件的特点:支持交友 N:想找到志同道合的人结伴出游,即可增进友谊,也可以提高出行的安全性. A:在景点下设置模块,可以看到其他人的出行计划,并可以相互交流,共同出游. B:这款软件可以让你交到朋友, ...

  4. paper 40 :鲁棒性robust

    最近只想安心.安静的科研,不想被任何人打扰,继续做自己,不忘初心,方得始终! 首先了解下鲁棒性这个词的定义.鲁棒性是指控制系统在一定(结构,大小)的参数摄动下,维持某些性能的特性.根据对性能的不同定义 ...

  5. Javascript之回调函数(callback)

    1.回调函数定义: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方 ...

  6. MVC架构剖析--ASP.NET MVC图解(二)

  7. 图像处理工具包ImagXpress教程:Accusoft不同组件间的图像数据传递

    图像处理工具包ImagXpress的开发厂商Accusoft Pegasus旗下有多种图像处理相关的控件,但是这些图像处理控件之间的如何加传递图像数据呢?在ImagXpress 11版本之前,是需要将 ...

  8. 终于有SpringMvc与Struts2的对比啦(转)

    本文转自:http://www.itsource.cn/web/news/5/20150318/370.html 目前企业中使用SpringMvc的比例已经远远超过Struts2,那么两者到底有什么区 ...

  9. SoupUI的使用

  10. JVM学习笔记(三)------内存管理和垃圾回收【转】

    转自:http://blog.csdn.net/cutesource/article/details/5906705 版权声明:本文为博主原创文章,未经博主允许不得转载. JVM内存组成结构 JVM栈 ...