【Codeforces Testing Round 12A】【讨论 边界元素映射】Divisibility 区间范围内k倍数的数的个数
来源:互联网 发布:淘宝卖包包店铺名字 编辑:程序博客网 时间:2024/06/08 11:05
#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;LL a,b,k;int main(){while(~scanf("%lld%lld%lld",&k,&a,&b)){LL lft=a/k;if(a>0&&a%k)++lft;LL rgt=b/k;if(b<0&&b%k)--rgt;printf("%lld\n",rgt-lft+1);}return 0;}/*【题意】给你一个模数k(1<=k<=1e18),然后再给你一个区间[a,b](-1e18<=a<=b<=1e18),问你这个区间内有多少个数,使得这个数为k的倍数。【类型】讨论【分析】第一个想法是,我们求出区间长度a-b+1,然后看这个区间长度是k的几倍。然而,问题很显然。比如说k=5,我们一个长度为6的区间内,k倍数的数可能是1个或2个。对于区间[0,5],k倍数的数为2个;对于区间[1,6],k倍数的数只有1个。于是我们发现,我们还需要特殊判定,处于边界位置的k倍数的数。既然如此,我们不妨直接映射到边界位置的k倍数的数——LL lft=a/k;if(a>0&&a%k)++lft;//最左的第一个数是lftLL rgt=b/k;if(b<0&&b%k)--rgt;//最右的第一个数是rgtprintf("%lld\n",rgt-lft+1);//答案就是rgt-lft+1做完喽!边界映射的思想棒棒哒!*/
0 0
- 【Codeforces Testing Round 12A】【讨论 边界元素映射】Divisibility 区间范围内k倍数的数的个数
- Codeforces 597 A. Divisibility 【Testing Round #12】
- Codeforces Testing Round #12 A. Divisibility( 容斥原理 )
- 【Codeforces Round 276 (Div 2)C】【讨论】Bits [l,r]范围内第1个数最多数中最小的那个
- 【Codeforces Testing Round 12B】【贪心】Restaurant 选取数量最多的不覆盖区间数
- 【Codeforces Round 339 (Div 2)A】【水题 暴力】 LinkCut Tree 输出[l,r]范围内所有的k的幂数
- CodeForces 597A Divisibility 在区间被整除的个数 暑假小练习R
- 【Codeforces Round 365 (Div 2)E】【乘除法DP map映射 约数分解】Mishka and Divisors n个数中选最小数量使得乘积为K的倍数
- CodeForces 597A Divisibility【二元一次方程(区间解数) 讨论)】
- 求 区间[a,b]内满足p^k*q*^m(k>m)的数的个数
- 得到[0~b]范围内A的倍数
- 【HDU5564 BestCoder Round 62 (div1)B】【DP转矩阵快速幂】Clarke and digits 长度在[l,r]范围内7倍数数个数要求相邻两位不为K
- 【Codeforces Round 324 (Div 2)A】【水题】Olesya and Rodion 构造数长度为n且是t的倍数
- 线段树离线处理(区间内出现k次的数有多少个)Codeforces Round #136 (Div. 2)
- 【Codeforces Testing Round 12C】【DP 树状数组优化】Subsequences n个不同数,长度为m的LIS数
- 求某个数范围内的素数个数
- 【Codeforces】Testing Round #12
- 随机生成某个范围内的随机数(包含边界数)
- 选择排序
- ImageLoader的MyApplication
- 第13周SHH数据结构-【项目4-Floyd算法的验证 】
- redis(二)
- matlab_GUI_2 radiobutton
- 【Codeforces Testing Round 12A】【讨论 边界元素映射】Divisibility 区间范围内k倍数的数的个数
- UE4 Light Shafts
- 玩转Highcharts图表库系列(三) 给曲线加上点击事件
- mybatis+spring 事务管理
- Eclipse启动时发生An internal error occurred during: "Initializing Java Tooling".错误的解决
- Java基础之程序
- 黑马程序员—Java基础—面向对象
- ImageWithColor
- DML触发器实现日志功能