Light OJ 1138

Source: Internet
Author: User

Trailing Zeroes (III)
Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld &%llu

Submit Status

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

Source

Problem Setter:jane Alam Jan

Arithmetical!!! Add two points ....

1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <math.h>5#include <iostream>6#include <algorithm>7#include <climits>8#include <queue>9 #definell Long LongTen  One  A using namespacestd; - ll ans; - ll Zero (ll num) the { -ll i,sum =0; -      for(i =5; I <= num; I *=5) -Sum + = num/i; +     returnsum; - } + voidCheckintN) A { atll low =5, Mid,high; -High =0x3f3f3f3f3f; -      while(Low <=High ) -     { -Mid = (Low+high)/2; -ll temp =Zero (mid); in          if(N <temp) -High = mid-1; to         Else if(N >temp) +Low = mid+1; -         Else if(n = =temp) the         { *             if(Mid = =Low ) $             {Panax NotoginsengAns =mid; -                 return; the             } +High =mid; A         } the     } + } -  $ intMainvoid) $ { -     intt,n,cnt =1; -Cin>>T; the      while(t--) -     {Wuyiscanf"%d",&n); theAns =-1; - check (n); Wu         if(ans = =-1) -printf"Case %d:impossible\n", cnt++); About         Else $printf"Case %d:%lld\n", cnt++, ans); -     } -     return 0; -}

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.