Divisibility(技巧)
2016-07-28 21:46
281 查看
给个数T,再给一个范围(m,n),求在此范围内能整除T的数有多少个......(技巧)
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long long t,a,b;
scanf("%lld %lld %lld",&t,&a,&b);
if(a<=0&&b>=0)
{
a=a/t;
b=b/t;
printf("%lld\n",b-a+1);
}
if(a>0)
{
if(a%t==0)
printf("%lld\n",(b/t-a/t)+1);
else
printf("%lld\n",(b/t-a/t));
}
if(b<0)
{
long long p=a;
a=-b;
b=-p;
if(a%t==0)
printf("%lld\n",(b/t-a/t)+1);
else
printf("%lld\n",(b/t-a/t));
}
return 0;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long long t,a,b;
scanf("%lld %lld %lld",&t,&a,&b);
if(a<=0&&b>=0)
{
a=a/t;
b=b/t;
printf("%lld\n",b-a+1);
}
if(a>0)
{
if(a%t==0)
printf("%lld\n",(b/t-a/t)+1);
else
printf("%lld\n",(b/t-a/t));
}
if(b<0)
{
long long p=a;
a=-b;
b=-p;
if(a%t==0)
printf("%lld\n",(b/t-a/t)+1);
else
printf("%lld\n",(b/t-a/t));
}
return 0;
}
相关文章推荐
- Android开发相关的Blog推荐——跟随大神的脚步才能成长为大神
- Android动画效果设置
- 关于一台电脑控制多台手机的技术分享被恶意转载的严正声明!
- MySQL必知必会面试题 基础
- MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
- SD卡读写问题
- yii框架中sphinx单条件搜索
- mysqldump原理及实践
- 【数据结构与算法】递归
- 用面向对象思想写钟表
- 优化移动设备上的实时阴影
- Java并发编程:Callable、Future和FutureTask
- aix 系统安装PostgreSQL数据库
- iOS NSDate等时间类的使用
- IP包头格式与IP地址分类
- 理解依赖注入(控制反转)!
- 【字符串】KMP匹配模板
- POJ 3170(bfs求最短路)
- NYOJ-68 三点顺序
- Zabbix-3.0.3使用自带模板监控MySQL