DEV Community

Cover image for Factorial
Gourav Kadu
Gourav Kadu

Posted on

2 2

Factorial

Click Here to read Problem Statement

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:
To run code click here

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();
}
}
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more