您的位置:首页 > 其它

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: