<|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; at multiples of higher powers of 5 it jumps by more, so some Q values are unreachable.
• 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 trailing_zeros(N) that computes Z(N). The implementation sweeps powers of 5 from the largest power not exceeding N down to 5, accumulating ⌊N/5^i⌋ in O(log_5 N).
b. Binary-search over N in [1, 2×10^12], a safe upper bound for Q up to 10^8:
   • mid = (low + high) // 2
   • if trailing_zeros(mid) ≥ Q, record mid and set high = mid − 1 to find a smaller candidate
   • else set low = mid + 1
c. After the loop, the recorded candidate is the smallest N with Z(N) ≥ Q.
d. Compute Z(candidate). If it equals Q, print it; otherwise print "No solution.".
Overall complexity: O(log(high) · log_5(high)), efficient for Q up to 10^8.

4. C++ Implementation
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int q;

void read() { cin >> q; }

int64_t trailing_zeros(int64_t x) {
    int64_t ret = 0, c = 0, cc = 1, l = 5;
    while(l <= x) {
        cc++;
        l *= 5ll;
    }

    while(l > 1) {
        ret += cc * (x / l - c);
        c += x / l - c;
        cc--;
        l /= 5ll;
    }

    return ret;
}

void solve() {
    // The number of trailing zeros of N! equals the exponent of 5 in N!,
    // i.e. floor(N/5) + floor(N/25) + floor(N/125) + ... This count is
    // non-decreasing in N, so we binary search for the smallest N whose
    // count is at least Q. If that minimal N actually hits exactly Q we
    // print it; since the count jumps by more than one at multiples of 25,
    // 125, ... some Q values are skipped entirely and we report "No
    // solution.". The count is evaluated by sweeping powers of 5 from the
    // largest not exceeding N down to 5.

    int64_t low = 1, high = (int64_t)2e12, ret = -1;
    while(low <= high) {
        int64_t mid = (low + high) >> 1;
        if(trailing_zeros(mid) >= q) {
            ret = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }

    if(trailing_zeros(ret) != q) {
        cout << "No solution.\n";
    } else {
        cout << ret << '\n';
    }
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    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 = 1, 2 * 10**12
    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()
```
