博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
172. Factorial Trailing Zeroes
阅读量:4701 次
发布时间:2019-06-09

本文共 501 字,大约阅读时间需要 1 分钟。

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Credits:

Special thanks to  for adding this problem and creating all test cases.

 

public class Solution {    public int trailingZeroes(int n) {      // math : n * n-1 * n-2...1 = 2 ^ x * 5 ^ y depend on y      int cnt = 0;      while(n > 0){          cnt += n/5;          n = n/5;  //26 or 126      }      return cnt;    }}

 

转载于:https://www.cnblogs.com/joannacode/p/6100251.html

你可能感兴趣的文章
C#读写三菱PLC和西门子PLC数据 使用TCP/IP 协议
查看>>
vue中moudles的作用及使用方法
查看>>
alpha版、beta版、rc版的意思
查看>>
负载均衡的常用算法
查看>>
JS版本 Bootstrap Modal
查看>>
Perl Coro初体检
查看>>
题目41:对称平方数
查看>>
算法分析:快速选择
查看>>
例题2-2 在屏幕上显示两个短句。
查看>>
梦断代码阅读笔记02
查看>>
Sunscreen [POJ3614] [贪心]
查看>>
网络 [HNOI2016]
查看>>
Java知多少(65)线程的挂起、恢复和终止
查看>>
数学学习笔记-函数
查看>>
一个博士生学位论文致谢部分
查看>>
PP学习笔记-业务基础
查看>>
HDU 3039 Go Home
查看>>
使用Grunt启动和运行
查看>>
哈希,最短路径,堆,排序,动态规划
查看>>
系统测试中需要注意的点
查看>>