E-wyh的阶乘

链接:https://www.nowcoder.com/acm/contest/93/E
来源:牛客网

Problem  Description:

这个问题很简单,就是问你n的阶乘末尾有几个0?

Input:

输入第一行一个整数T(1<=T<=100),代表测试组数

接下来T行,每行一个数n(1<=n<=10^9)

Output:

对于每组测试数据,输出对应答案

Sample  Input:

5
1
2
3
4

5

Sample  Output:

0
0
0
0

1

思路:记住这种简单的方法,以后可能还有用。至于为什么,自己摸索,因为我也不知道。。

My  DaiMa:

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int t,n,y;
    cin>>t;
    while(t--)
    {
        y=0;
        cin>>n;
        while(n)
        {
            n/=5;
            y+=n;
        }
        cout<<y<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41181772/article/details/79878577