<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

154. Factorial
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output



You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.

Input
One number Q written in the input (0<=Q<=10^8).

Output
Write "No solution", if there is no such number N, and N otherwise.

Sample test(s)

Input
2

Output
10
Author:	Andrew V. Lazarev
Resource:	Saratov Subregional School Team Contest, 2002
Date:	Spring, 2002

<|response|>
1. Abridged Problem Statement  
Given a non-negative integer Q (0 ≤ Q ≤ 10^8), find the smallest positive integer N such that the decimal representation of N! ends with exactly Q zeros. If no such N exists, print “No solution.”.

2. Key Observations  
• Each trailing zero in N! is created by a factor 10 = 2×5. In the product 1·2·…·N there are always more factors of 2 than 5, so the number of trailing zeros Z(N) is determined by the exponent of 5 in N!.  
• The exponent of 5 in N! is  
 Z(N) = ⌊N/5⌋ + ⌊N/5²⌋ + ⌊N/5³⌋ + …  
  stopping when 5^k > N.  
• Z(N) is a non-decreasing function of N and increases by at least 1 at each multiple of 5.  
• We can therefore binary-search N to find the minimal N for which Z(N) ≥ Q, and then check if Z(N) == Q.

3. Full Solution Approach  
a. Define a function eval(N) that computes Z(N) by summing N/5 + N/25 + N/125 + … in O(log_5 N).  
b. Set search bounds: low = 0, high = 5×(Q+1). Why 5×(Q+1)? Roughly Z(N) ≈ N/4, so N ≈ 4Q suffices, and 5(Q+1) is a safe upper bound.  
c. Binary-search while low ≤ high:  
   • mid = (low + high) // 2  
   • if eval(mid) ≥ Q, record mid and set high = mid − 1 to find a smaller candidate  
   • else set low = mid + 1  
d. After the loop, low (or the recorded candidate) is the smallest N with Z(N) ≥ Q.  
e. Compute Z(low). If it equals Q, print low; otherwise print “No solution.”.  
Overall complexity: O(log(high) · log_5(high)) ≈ O(log Q · log Q), which is efficient for Q up to 10^8.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

// Compute the number of trailing zeros in N!
int64 trailingZeros(int64 n) {
    int64 count = 0;
    // Sum floors of n / 5^k
    for (int64 p = 5; p <= n; p *= 5) {
        count += n / p;
        // avoid overflow: if p > n/5, next p*=5 would overflow or be > n
        if (p > n / 5) break;
    }
    return count;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int64 Q;
    if (!(cin >> Q)) return 0;

    // Binary search for minimal N with at least Q zeros
    int64 low = 0, high = 5 * (Q + 1), ans = -1;
    while (low <= high) {
        int64 mid = (low + high) / 2;
        if (trailingZeros(mid) >= Q) {
            ans = mid;
            high = mid - 1;  // try to find a smaller N
        } else {
            low = mid + 1;
        }
    }

    // Check if we found an exact match
    if (ans >= 0 && trailingZeros(ans) == Q) {
        cout << ans << "\n";
    } else {
        cout << "No solution\n";
    }
    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys

def trailing_zeros(n):
    """
    Return the number of trailing zeros in n! by summing
    floor(n/5) + floor(n/25) + floor(n/125) + ...
    """
    count = 0
    power = 5
    while power <= n:
        count += n // power
        power *= 5
    return count

def find_min_n(Q):
    """
    Binary-search the smallest n such that trailing_zeros(n) >= Q.
    """
    low, high = 0, 5 * (Q + 1)
    answer = -1
    while low <= high:
        mid = (low + high) // 2
        if trailing_zeros(mid) >= Q:
            answer = mid
            high = mid - 1
        else:
            low = mid + 1
    return answer

def main():
    data = sys.stdin.read().strip()
    if not data:
        return
    Q = int(data)
    n = find_min_n(Q)
    # Verify exact match
    if n >= 0 and trailing_zeros(n) == Q:
        print(n)
    else:
        print("No solution")

if __name__ == "__main__":
    main()
```