-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactorialTrailingZeroes.java
More file actions
48 lines (39 loc) · 1009 Bytes
/
FactorialTrailingZeroes.java
File metadata and controls
48 lines (39 loc) · 1009 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
import org.junit.Test;
public class FactorialTrailingZeroes {
/*public int trailingZeroes(int n) {
long res = factorial(n);
int zoreCount = 0;
while (res != 0) {
long reminder = res % 10;
if (reminder == 0) zoreCount++;
else break;
res /= 10;
}
return zoreCount;
}
*//*public static long factorial(int n) {
int res = 1;
while (n != 0) {
res = n * res;
n--;
}
return res;
}*//*
public static int factorial(int n) {
if (n == 0 || n == 1) return 1;
return n * factorial(n - 1);
}*/
public int trailingZeroes(int n) {
int zero_num = 0;
while (n != 0){
n = n/5;
zero_num += n;
}
return zero_num;
}
@Test
public void test() {
// 120 -> 24
System.out.println(trailingZeroes(7));
}
}