返回

#yyds干货盘点# 名企真题专题:末尾0的个数

发布时间:2023-01-03 15:43:17 280

1.简述:

描述

输入一个正整数n,求n!(即阶乘)末尾有多少个0? 比如: n = 10; n! = 3628800,所以答案为2

输入描述:

输入为一行,n(1 ≤ n ≤ 1000)

输出描述:

输出一个整数,即题目所求

示例1

输入:

10

输出:

2

2.代码实现:

public class Main{

public static int test(int n){
if(n < 0){
return 0;
}
int res = 0;
while (n !=0){
res += n /5;
n = n/5;
}
return res;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
System.out.println( test(in.nextInt()));
}
}
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线