0710 编程之美之N!末尾0的个数

来源:互联网 发布:开实体店在淘宝上拿货 编辑:程序博客网 时间:2024/05/21 18:32
#include<iostream>using namespace std;int main_()//解法1{    int n;    while (cin >> n)    {        int count = 0;        for (int i = 1; i <= n; ++i)        {            int j = i;            while (j%5==0)            {                count++;                j = j/ 5;            }        }        cout << count << endl;    }    return 0;}int main()//解法2{    int n;    while (cin >> n)    {        int count = 0;        while (n)        {            count += n / 5;            n /= 5;        }        cout << count << endl;    }    cin.get();    return 0;}
原创粉丝点击