Solution1: 1 class Solution { 2 public: 3 int trailingZeroes(int n) { 4 long int temp = factorial(n); 5 int count = 0; 6 b...
分类:
其他好文 时间:
2015-04-10 20:03:48
阅读次数:
133
题意:求一个整数的阶乘的尾数0的个数。分析:**方法一:**对n!做质因数分解n!=2x?3y?5z?...n!=2^x*3^y*5^z*... 显然0的个数等于min(x,z)min(x,z),并且min(x,z)==zmin(x,z)==z,也就是5的幂指数。
证明:
对于阶乘而言,也就是N!=1?2?3?...?nN!=1*2*3*...*n
[n/2]>[n/5][n/2] > [n/...
分类:
其他好文 时间:
2015-04-07 12:04:06
阅读次数:
108
1、题目要求Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.题目意思是求n的阶乘后面末尾0的个数,并且时间...
分类:
其他好文 时间:
2015-04-04 18:09:00
阅读次数:
110
Factorial Trailing Zeroes问题:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.思...
分类:
其他好文 时间:
2015-04-02 18:26:49
阅读次数:
117
Given an integern, return the number of trailing zeroes inn!.最初的代码class Solution {public: int trailingZeroes(int n) { long long int fac = 1; ...
分类:
其他好文 时间:
2015-03-30 16:18:19
阅读次数:
121
function factorial(num){ if(num<=1){ return 1; }else{ return num = num * factorial(num-1); }}改进function factorial(num){ if(n...
分类:
其他好文 时间:
2015-03-28 17:04:31
阅读次数:
118
Think about that.. n! = n * (n-1) * (n-2) ..... *1Zeros happened when each of them can be divided by 10. And 10 = 2 * 5. 2 is much more than 5 in the ...
分类:
其他好文 时间:
2015-03-19 10:01:03
阅读次数:
140
Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.解析: 只有2和5相乘才会出现0,其中整十也可以看做是2和...
分类:
其他好文 时间:
2015-03-17 19:47:19
阅读次数:
136
Go support recursive functions. Here's a classic factorial examplepackage mainimport ( "fmt")func fact(n int) int { if n == 0 { return 1 ...
分类:
其他好文 时间:
2015-03-14 18:18:24
阅读次数:
105
Problem Description
The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest ...
分类:
其他好文 时间:
2015-03-14 17:03:59
阅读次数:
201