## DEV Community is a community of 850,025 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Posted on

# Factorial

Input:
There is a single positive integer T on the first line of input (equal to about 100000). It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1≤N≤109.

Output:
For every number N, output a single line containing the single non-negative integer Z(N).

Sample Input:
6
3
60
100
1024
23456
8735373

Sample Output:
0
14
24
253
5861
2183837

Solution:

``````import java.util.*;
public class Template {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum1=0;

int arr[] = new int[n];
for(int i= 0; i<n;i++) {
arr[i] = sc.nextInt();
}

for(int i = 0 ; i<n; i++) {
if(arr[i]<5) {
System.out.println("0");
}else {

int temp = arr[i];

while(temp != 0) {
temp = temp/5;
sum1+=temp;

}

System.out.println(sum1);
sum1=0;
temp=0;
}
}
sc.close();
}
}
``````