Codeforces 597 A. Divisibility 【Testing Round #12】
2015-11-12 19:01
519 查看
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 k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
Output
Print the required number.
Sample test(s)
input
output
input
output
题目大意:
给你三个数 n, a, b,让你求a 到 b的区间内有几个数能够被 k 整除。。。
直接上代码吧。。。
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 k, a 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
题目大意:
给你三个数 n, a, b,让你求a 到 b的区间内有几个数能够被 k 整除。。。
直接上代码吧。。。
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <algorithm> #include <set> #include <stack> using namespace std; #define MM(a) memset(a,0,sizeof(a)) typedef long long LL; typedef unsigned long long ULL; const int maxn = 1e2+5; const int INF = 1e9+5; const int mod = 1000000007; const double eps = 1e-7; LL gcd(LL a, LL b) { if(b == 0) return a; return gcd(b, a%b); } int main() { LL a, b, k; while(cin>>k>>a>>b) { if(b <= 0) { a = -a; b = -b; swap(a, b); } LL ans = b/k-a/k; if(a%k==0 || a<0) ans++; cout<<ans<<endl; } return 0; }
相关文章推荐
- 作业调度模拟程序
- Spring 4.x框架中的新特性---4.1中的新功能和提升
- iOS开发零基础教程之真机调试流程
- thinkphp框架项目在火狐浏览器上通过uploadify上传图片提示“302”问题
- Android中的Handler与Looper
- 拖入itunes打包ipa提示“这台电脑上已存在一个名为“embedded.mobileprovision”的预置文件。您要替换它吗?”问题解决
- 语音的基本概念--译自CMU sphinx
- 解决 “无法安装 Visual Studio 2010 Service Pack 1,因为此计算机的状态不支持”
- Java 自定义注解及利用反射读取注解
- iOS开发零基础教程之上传AppStore流程
- Activity的四大启动模式(launchMode)
- Android学习之Asynctask异步操作
- 1112实验二 作业调度模拟程序
- AsyncTask的简单使用
- OC容易遗漏点得知识整理
- iOS开发零基础教程之开发证书以及打包问题
- sqlserver不能直接create table as select ......
- 实验二 作业调度模拟程序
- 关于android 三种jar包导入方式的备注
- [LeetCode]75. Pow(x,n)幂运算