(binary search number theory) (factorial of 0 numbers in factorial) light OJ--1138

Source: Internet
Author: User

Link

Description

You task was 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! = 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

Code:

#include <cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<queue>#include<stack>#include<algorithm>using namespacestd;#defineN 0x3f3f3f3fintNUM0 (intN) {    intsum =0;  while(n) {sum+ = n/5; N/=5; }    returnsum;}voidSearch (intW///Two-point search{    intL=0, r=N, Mid;  while(l<=R) {Mid= (l+r) >>1; if(W <=NUM0 (mid)) R= Mid-1; ElseL= Mid +1; }    if(NUM0 (L) = =W) printf ("%d\n", L); Elseprintf ("impossible\n");}intMain () {intIcase=1, N, t; scanf ("%d", &t);  while(t--) {scanf ("%d", &N); printf ("Case %d:", icase++);    Search (n); }    return 0;}

(binary search number theory) (factorial of 0 numbers in factorial) light OJ--1138

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.