您的位置:首页 > 其它

UVALive 6847 Zeroes(规律)

2015-12-11 22:08 543 查看
题意:

求0≤L≤R≤9×1018所有数的阶乘末尾0个数不相同的数的个数

分析:

打表发现0的个数周期是0,0,0,0,1,1,1,1,1,...,n,n,n,n,n

第一个是4,后面其他的都是5,然后判断L,R在分别在哪个周期即可

代码:

#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;
//4 5
LL l, r;

LL calc(LL x) {
if(x < 4) return 1;
return (x - 4 + 5 - 1) / 5 + 1;
}

int main() {
while(scanf("%lld%lld", &l, &r) == 2 && (l || r)) {
printf("%lld\n", calc(r) - calc(l) + 1);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  规律