You are given a positive integer N. Your task is to find the smallest number whose factorial contains at least N trailing zeroes.
Example :Let N = 1. The smallest number whose factorial contains at least 1 trailing zeroes is 5 as 5! = 120.
The very first line of input contains an integer ‘T’ denoting the number of test cases.
The first line and only line of every test case contain an integer ‘N’ denoting the number of trailing zeros.
Output format :
For each test case, the smallest number whose factorial contains at least N trailing zeroes is printed.
Output for each test case is printed on a separate line.
Note :
You do not need to print anything, it has already been taken care of. Just return the answer.
1 <= T <= 10
0 <= N <= 10^8
Time Limit: 1 sec
2
1
2
5
10
For the first test case, refer to the example explained above.
For the second test case, we have, N = 2.
The smallest number whose factorial contains at least 2 trailing zeros is 10 as 10! = 36,28,800.
2
3
0
15
0
Can you solve this problem by generating all the factorials?
O(M), where M is the smallest number whose factorial contains at least N trailing zeroes.
We are calculating all the factorials from 0 to M which requires O(M) time. For each factorial, we are counting the number of trailing zeros which requires constant time. Hence, the overall time complexity is O(M). Note that M! can be very large for large values of N.
O(1)
Only constant extra space is required.