Testing Round #12 A
1 second
256 megabytes
standard input
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.
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
Print the required number.
1 1 10
10
2 -4 4
5 不得不说,这题的思路和上一个一样的
#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的更多相关文章
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp
题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...
- Testing Round #12 B
Description A restaurant received n orders for the rental. Each rental order reserve the restaurant ...
- Testing Round #12 C
Description For the given sequence with n different elements find the number of increasing subsequen ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...
随机推荐
- nyist 596 谁是最好的Coder
http://acm.nyist.net/JudgeOnline/problem.php?pid=596 谁是最好的Coder 时间限制:1000 ms | 内存限制:65535 KB 难度:0 ...
- php 警告
php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...
- 软件需求分析之NABCD模型
软件的特点:支持交友 N:想找到志同道合的人结伴出游,即可增进友谊,也可以提高出行的安全性. A:在景点下设置模块,可以看到其他人的出行计划,并可以相互交流,共同出游. B:这款软件可以让你交到朋友, ...
- paper 40 :鲁棒性robust
最近只想安心.安静的科研,不想被任何人打扰,继续做自己,不忘初心,方得始终! 首先了解下鲁棒性这个词的定义.鲁棒性是指控制系统在一定(结构,大小)的参数摄动下,维持某些性能的特性.根据对性能的不同定义 ...
- Javascript之回调函数(callback)
1.回调函数定义: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方 ...
- MVC架构剖析--ASP.NET MVC图解(二)
- 图像处理工具包ImagXpress教程:Accusoft不同组件间的图像数据传递
图像处理工具包ImagXpress的开发厂商Accusoft Pegasus旗下有多种图像处理相关的控件,但是这些图像处理控件之间的如何加传递图像数据呢?在ImagXpress 11版本之前,是需要将 ...
- 终于有SpringMvc与Struts2的对比啦(转)
本文转自:http://www.itsource.cn/web/news/5/20150318/370.html 目前企业中使用SpringMvc的比例已经远远超过Struts2,那么两者到底有什么区 ...
- SoupUI的使用
- JVM学习笔记(三)------内存管理和垃圾回收【转】
转自:http://blog.csdn.net/cutesource/article/details/5906705 版权声明:本文为博主原创文章,未经博主允许不得转载. JVM内存组成结构 JVM栈 ...