1340-story of Tomisu Ghost

Source: Internet
Author: User

1340-story of Tomisu Ghost
PDF (中文版) Statistics Forum
Time Limit:2 second (s) Memory limit:32 MB

It is now 2150 AD and problem-setters be have a horrified time as the ghost of a problem-setter from the past, Mr. T Omisu, is frequently disturbing them. As always are the case in most common ghost stories, Mr Tomisu have an unfulfilled dream:he had set 999 problems Throughou T he whole life never had the leisure to set the 1000th problem. Being a ghost He cannot set problems now and he randomly asks Problem-setters to complete one of the his unfinished problems. One problem-setter tried to convince him saying the he should not regret as 999 are nowhere near 1024x768 and he should Not worry about power of ten being an IT ghost. But the ghost slapped him hard after hearing this. So at the last one problem setter decides to complete his problem:

"n! (factorial n) have at least T trailing zeroes in B based number system. Given the value of n and T, what is the maximum possible value of B? "

Input

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

Each case contains the integers N (1 < n≤105) and t (0 < t≤1000). Both n and T be is given in decimal (base 10).

Output

For each case, print the case number and the maximum possible value of B. Since b Can is very large, so print b modulo 10000019. If such a base cannot is found then print -1 instead.

Sample Input Output for Sample Input

4

1000 1000

1000 2

10 8

4 2

Case 1:-1

Case 2:5,227,616

Case 3:2

Case 4:2

Problem Setter:shahriar manzoorspecial thanks:jane Alam Jan, Md. Towhidul Islam talukder idea: Very simple, as long as the first number of factorial prime decomposition, and then each factor of the Number requires the number of the end 0 and then the answer *power (pi,ans/m), in fact, is to write a number k*d^m;
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <cmath>5#include <iostream>6#include <algorithm>7#include <map>8#include <queue>9#include <vector>Ten using namespacestd; OnetypedefLong LongLL; A Const intn=10000019; - BOOLprime[100005]; - intans_prime[100005]; the intfen_prime[100005]; - ll Quick (ll n,ll m); - intMainvoid) - { +         inti,j,k; -         intan=0; +          for(i=2; i<=100000; i++) A         { at                 if(!Prime[i]) -                 { -                          for(J=i; (LL) i* (LL) j) <=100000; J + +) -                         { -prime[i*j]=true; -                         } inans_prime[an++]=i; -                 } to         } +         int__ca=0; -scanf"%d",&k); the          while(k--) *         { $__ca++;Panax Notoginseng LL n,m; -scanf"%lld%lld",&n,&m); thememset (Fen_prime,0,sizeof(Fen_prime)); +                  for(i=0; i<an; i++) A                 { theLL ask=N; +                         if(ask<Ans_prime[i]) -                         { $                                  Break; $                         } -                         Else -                         { the                                  while(ASK) -                                 {Wuyifen_prime[i]+=ask/Ans_prime[i]; theAsk/=Ans_prime[i]; -                                 } Wu                         } -                         if(fen_prime[i]<m) About                              Break; $                 } -LL anw=1; -                  for(i=0; i<an;i++) -                 { A                     if(fen_prime[i]<m) +                     { the                          Break; -                     } $                     Else the                     { theAnw= (Anw*quick (ans_prime[i],fen_prime[i]/m))%N; the                     } the                 } -printf"Case %d:", __ca); in                 if(anw==1) the                 { theprintf"-1\n"); About                 } the                 Else the                 { theprintf"%lld\n", ANW); +                 } -         } the         return 0;Bayi } the ll Quick (ll n,ll m) the { -LL ak=1; -          while(m) the         { the                 if(m&1) the                 { theak=ak*n%N; -                 } then=n*n%N; theM/=2; the         }94         returnAK; the}

1340-story of Tomisu Ghost

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.