LightOJ - 1138 N - Trailing Zeroes (III)

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

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains an integer Q (1 ≤ Q ≤ 108) in a line.

Output

For each case, print the case number and N. If no solution is found then print 'impossible'.

Sample Input

3

1

2

5

Sample Output

Case 1: 5

Case 2: 10

Case 3: impossible

题意:求 N ! 末尾 0 的个数为 Q 个的数?

分析:之前做过类似的一道题,每包含一个5,就有一个0,不过由于N的范围太大,所以用二分来做。

代码:

#include
#include
#include
using namespace std;
const int N=500000000;
int solve(int n)  //统计0的个数
{
    int sum=0;
    while(n)
    {
        sum+=n/5;
        n=n/5;
    }
    return sum;
}
int he(int n)   //二分
{
    int l,r,mid;
    l=0,r=N;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(solve(mid)

 

你可能感兴趣的:(LightOJ - 1138 N - Trailing Zeroes (III))