51nod 1003 阶乘后面0的数量

n的阶乘后面有多少个06的阶乘 = 1*2*3*4*5*6 = 720720后面有10。
Input
一个数N(1 <= N <= 10^9)
Output
输出0的数量
Input示例
5
Output示例
1
这道题看到的时候就是找规律啦。
对任意一个正整数,对其进行因式分解,其末尾的0必定可以分解2x5,
每一个0必定和一个因子5对应,但是一个数的因式分解中因子5不一定
对应着一个0,还需要一个因子2才能实现与之一一对应。对于n!,因式
分解中,2的因子个数要大于5的因子个数,如果存在一个5,那么它必定
对应n!末尾的一个0,所以本题就是求5的因子的个数。
n/p+[n/p^2]+[n/p^3]+[n/p^4]+...
例如:
5,1~9只能分别出一个5的因子,所以是1.
5,1~24,分解出45的因子,所以是4.
5,1~2525之前就45的因子,而25能分解出25的因子,所以sum=4+25/5^2=6,
...
以此类推。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<ctime>
#include<string>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<cstdio>
#include<limits.h>
#define MOD 1000000007
#define fir first
#define sec second
#define fin freopen("/home/ostreambaba/文档/input.txt", "r", stdin)
#define fout freopen("/home/ostreambaba/文档/output.txt", "w", stdout)
#define mes(x, m) memset(x, m, sizeof(x))
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define INF 1e9+7
#define Pi 4.0*atan(1.0)

#define lowbit(x) (x&(-x))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-12;
const int maxn = 35;
using namespace std;

inline int read(){
    int x(0),op(1);
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')op=-1,ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*op;
}
int main()
{
    int n;
    n=read();
    int sum=0;
    int theFive=5;
    while(theFive<=n){
        sum+=n/theFive;
        theFive*=5;
    }
    cout<<sum<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值