-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNTrailingZeros.cc
37 lines (34 loc) · 931 Bytes
/
NTrailingZeros.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* =====================================================================================
*
* Filename: TrailingZeros.cc
*
* Description: Program to find number of trailing zeros
*
* Version: 1.0
* Created: 01/26/12 12:05:55
* Revision: none
* Compiler: gcc
*
* Author: Ganesh Muniyandi (gm), [email protected]
* Company: Open Source
*
* =====================================================================================
*/
#include <iostream>
unsigned int NTrailingZeros(unsigned int N) {
unsigned int result = 0;
unsigned int divisor = 5;
while(true) {
unsigned int t = N / divisor;
if (!t) break;
result += t;
divisor *= 5;
}
return result;
}
int main() {
for(unsigned int i=0; i<1000000000; ++i)
std::cout << i << " ==> " << NTrailingZeros(i) << std::endl;
return 0;
}