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在分别在哪个周期即可
代码:
求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; }
相关文章推荐
- 为什么我们不能坚持到底?
- nVIDIA显卡命名规律
- 人才成长有其自身的规律
- Spiral——找规律暴力
- HDU 5491 The Next
- HDU 1005 Number Sequence
- HDU 1061 Rightmost Digit
- [2013山东省第四届ACM大学生程序设计竞赛]——Alice and Bob
- 【打CF,学算法——三星级】Codeforces 9C Hexadecimal's Numbers (解法汇总)
- hdu 4519
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- NY--854 -- 留恋
- 2015南阳ccpc L题
- HDOJ1517[K(2~9)倍博弈][有规律存在]
- POJ2484(水博弈)
- ZOJ 2686(规律博弈)
- HDU 4642 多校四-1011
- HDU 5587 Array (规律)
- 【hdoj 1005】有限状态机
- Number Sequence_hdu_1005(规律)