当前位置: 首页 > news >正文

牛客 NC129 阶乘末尾0的数量【简单 基础数学 Java/Go/PHP/C++】

题目

在这里插入图片描述
题目链接:
https://www.nowcoder.com/practice/aa03dff18376454c9d2e359163bf44b8
https://www.lintcode.com/problem/2

思路

在这里插入图片描述

Java代码

import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** the number of 0* @param n long长整型 the number* @return long长整型*/public long thenumberof0 (long n) {//就是可以转换成求有多少个5,然后求每个5的倍数的数中有多少个5.最后将所有5的个数加一起long ans =0;while(n > 0){n =n/5;ans+=n;}return ans;}
}

Go代码

package main/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** the number of 0* @param n long长整型 the number* @return long长整型*/
func thenumberof0(n int64) int64 {//就是可以转换成求有多少个5,然后求每个5的倍数的数中有多少个5.最后将所有5的个数加一起var ans int64= 0for n > 0 {n = n / 5ans += n}return ans
}

PHP代码

<?php/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** the number of 0* @param n long长整型 the number* @return long长整型*/
function thenumberof0( $n )
{//就是可以转换成求有多少个5,然后求每个5的倍数的数中有多少个5.最后将所有5的个数加一起$ans =0;while($n >0){$n = intval($n/5);$ans+=$n;}return $ans;
}

C++代码

class Solution {
public:/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** the number of 0* @param n long长整型 the number* @return long长整型*/long long thenumberof0(long long n) {//就是可以转换成求有多少个5,然后求每个5的倍数的数中有多少个5.最后将所有5的个数加一起long ans =0;while(n >0){n=n/5;ans+=n;}return ans;}
};
http://www.lryc.cn/news/368163.html

相关文章:

  • 【Spring Boot】异常处理
  • Laravel学习-自定义辅助函数
  • LLVM Cpu0 新后端6
  • GAT1399协议分析(9)--图像上传
  • Spring ApplicationContext的getBean方法
  • 自然语言处理(NLP)—— 自动摘要
  • Spring RestClient报错:400 Bad Request : [no body]
  • 【数据结构】 -- 堆 (堆排序)(TOP-K问题)
  • C#面:XML与 HTML 的主要区别是什么
  • java并发-如何保证线程按照顺序执行?
  • PyCharm中 Fitten Code插件的使用说明一
  • Polar Web【简单】PHP反序列化初试
  • 树莓派4B 零起点(二) 树莓派 更换软件源和软件仓库
  • Pytorch 实现目标检测二(Pytorch 24)
  • 如何使用Python中的列表解析(list comprehension)进行高效列表操作
  • java使用websocket遇到的问题
  • [Cloud Networking] Layer 2
  • [240609] qwen2 发布,在 Ollama 已可用 | 采用语言模型构建通用 AGI(2020年8月)
  • 赶紧收藏!2024 年最常见 20道分布式、微服务面试题(五)
  • 为什么Kubernetes(K8S)弃用Docker:深度解析与未来展望
  • 软件游戏提示msvcp120.dll丢失的解决方法,总结多种靠谱的解决方法
  • 使用kafka tools工具连接带有用户名密码的kafka
  • [个人感悟] Java基础问题应该考察哪些问题?
  • MySQL-主从复制
  • 开发没有尽头,尽力既是完美
  • 【手推公式】如何求SDE的解(附录B)
  • STM32F103单片机工程移植到航顺单片机HK32F103注意事项
  • Llama模型家族之Stanford NLP ReFT源代码探索 (四)Pyvene论文学习
  • rapidjson 打包过程插入对象
  • NVeloDocx一个基于NVelocity的word模版引擎