题解 | #阶乘末尾0的数量#

阶乘末尾0的数量

https://www.nowcoder.com/practice/aa03dff18376454c9d2e359163bf44b8

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * the number of 0
     * @param n long长整型 the number
     * @return long长整型
     */
    long long thenumberof0(long long n) {
        // write code here
        long long result = 0;
        long long temp = 5;
        while (n >= temp) {
            result += n / temp;
            temp = temp * 5;
        }

        return result;
    }
};

全部评论

相关推荐

09-25 23:37
已编辑
桂林电子科技大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务