Story of Tomisu Ghost
It's now 2150 AD and problem-setters be have a horrified time as the ghost of a problem-setter from the past, Mr Tomi Su, 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 -1instead.
Sample Input
| 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 |
Source
Test Instructions : give you a n,t, the factorial of n in the size of the number of B, the number of tails has T 0, ask the largest B is how much, there is no B output-1;
Solution: The number of tails have T 0, that is, B has t-times relationship, we will 1-n the number of all quality factors to find out, whether there is greater than or equal to T can add the answer, otherwise-1
///1085422276#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_backinline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){ if(ch=='-') f=-1; ch=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar (); }returnx*F;}//****************************************Const DoublePI =3.1415926535897932384626433832795;Const DoubleEPS = 5e-9;#defineMAXN 100000+5#defineMoD 10000019intN,t,h[maxn],hh[maxn];vector<int>G[maxn],p;ll POWs (ll x,ll TT) {ll tmp=1; for(intI=1; i<=tt;i++) {tmp= (tmp*x)%MoD; } returntmp;}intMain () {intan=0; mem (HH); for(intI=2; i<=100000; i++) { if(!Hh[i]) {P.PB (i); for(intj=i+i;j<=100000; j+=i) {hh[j]=1; } } } intT=read (), oo=1; while(t--) {mem (H); intflag=0; N=read (), t=read (); printf ("Case %d:", oo++); ll ans=1; for(intk=0; K<p.size () &&p[k]<=n;k++) {ll C=p[k],tt=0; ll y=n/Z; while(y) {TT+=y; Y=y/Z; } if(tt>=t) {Flag=1; Ans= (Ans*pows (c,tt/t))%10000019; } } if(!flag) printf ("-1\n"); Elseprintf ("%lld\n", ans); } return 0;}Code
BNU 13259.Story of Tomisu Ghost decomposition factor