扩展1000!(n!)的尾数零的个数

#include <stdio.h>
#include <malloc.h>
//计算1000!尾数零的个数
//扩展n!的尾数零的个数
//2^a * 5^b
//obviously a>b
//so count = b
//5*1 5*2 .....5*200  200个  除以5
//1 2 3 4 5 .... 200 中 包含 5*(1,2,3,4,...40) 40个 除以5
//5*1 5*2 ..... 5*8

void calc1(int n){
    int count=0;
    int i=1,t;
    for(;i<=n;i++)
    {
        t = i;
        while(t%5==0)
        {
            count++;
            t = t/5;
        }
    }
    printf("%d",count);
}

void calc2(int n)
{
    int sum=0;
    while(n)
    {
        n/=5;
        sum+=n;
    }
    printf("%d",sum);
}

int main () {
    int n = 1000;
    calc2(n);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/czsblog/p/10584225.html
今日推荐