DEV Community

Cover image for Factorial
Gourav Kadu
Gourav Kadu

Posted on

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

Top comments (0)