1340 - Story of Tomisu Ghost
Time Limit: 2 second(s) Memory Limit: 32 MB

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

"n! (factorial n) has 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 two integers n (1 < n ≤ 105) and t (0 < t ≤ 1000). Both n and t will be given in decimal (base 10).

Output

For each case, print the case number and the maximum possible value of b. Since b can be very large, so print b modulo 10000019. If such a base cannot be 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: 5227616

Case 3: 2

Case 4: 2


Problem Setter: Shahriar Manzoor
Special Thanks: Jane Alam Jan, Md. Towhidul Islam Talukder
思路:很简单,只要将前面的数的阶乘素数分解,然后将每个因子的个数要求末尾0的个数然后答案*power(pi,ans/m);
其实就是把一个数写成k*d^m;中d的数值;
 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>
10 using namespace std;
11 typedef long long LL;
12 const int N=10000019;
13 bool prime[100005];
14 int ans_prime[100005];
15 int fen_prime[100005];
16 LL quick(LL n,LL m);
17 int main(void)
18 {
19 int i,j,k;
20 int an=0;
21 for(i=2; i<=100000; i++)
22 {
23 if(!prime[i])
24 {
25 for(j=i; ((LL)i*(LL)j)<=100000; j++)
26 {
27 prime[i*j]=true;
28 }
29 ans_prime[an++]=i;
30 }
31 }
32 int __ca=0;
33 scanf("%d",&k);
34 while(k--)
35 {
36 __ca++;
37 LL n,m;
38 scanf("%lld %lld",&n,&m);
39 memset(fen_prime,0,sizeof(fen_prime));
40 for(i=0; i<an; i++)
41 {
42 LL ask=n;
43 if(ask<ans_prime[i])
44 {
45 break;
46 }
47 else
48 {
49 while(ask)
50 {
51 fen_prime[i]+=ask/ans_prime[i];
52 ask/=ans_prime[i];
53 }
54 }
55 if(fen_prime[i]<m)
56 break;
57 }
58 LL anw=1;
59 for(i=0;i<an;i++)
60 {
61 if(fen_prime[i]<m)
62 {
63 break;
64 }
65 else
66 {
67 anw=(anw*quick(ans_prime[i],fen_prime[i]/m))%N;
68 }
69 }
70 printf("Case %d: ",__ca);
71 if(anw==1)
72 {
73 printf("-1\n");
74 }
75 else
76 {
77 printf("%lld\n",anw);
78 }
79 }
80 return 0;
81 }
82 LL quick(LL n,LL m)
83 {
84 LL ak=1;
85 while(m)
86 {
87 if(m&1)
88 {
89 ak=ak*n%N;
90 }
91 n=n*n%N;
92 m/=2;
93 }
94 return ak;
95 }
 

1340 - Story of Tomisu Ghost的更多相关文章

  1. LightOJ 1340 - Story of Tomisu Ghost 阶乘分解素因子

    http://www.lightoj.com/volume_showproblem.php?problem=1340 题意:问n!在b进制下至少有t个后缀零,求最大的b. 思路:很容易想到一个数通过分 ...

  2. BNU 13259.Story of Tomisu Ghost 分解质因子

    Story of Tomisu Ghost It is now 2150 AD and problem-setters are having a horrified time as the ghost ...

  3. 使用 Ghost 写博客

    今天在https://ghost.org/上试用了一会,发现这是一个出色的博客平台,相比WordPress,更轻量级,而且是使用Node.js来做的,性能也是非常的不错. 优点 轻量级 支持主题 支持 ...

  4. 最新GHOST XP系统下载旗舰增强版 V2016年

    系统来自:系统妈:http://www.xitongma.com 深度技术GHOST xp系统旗舰增强版 V2016年3月 系统概述 深度技术ghost xp系统旗舰增强版集合微软JAVA虚拟机IE插 ...

  5. 最新win7系统64位和32位系统Ghost装机稳定版下载

    系统来自转载:系统妈 一.主要更新:========================== * 更新了系统补丁和Office2007 SP2所有补丁 通过微软漏洞扫描* 更新QQ至7.1  官方正式版* ...

  6. 用Ghost进行备份还原

    今天给大伙介绍一下怎么用Ghost给自己的系统进行备份和还原,在这里我用的是U盘启动盘(电脑店)里面的手动Ghost.   首先给大家介绍一下Ghost界面的一些相关选项的含义:(虽然难看但希望大伙们 ...

  7. ubuntu14.04上Virtualbox安装win7(使用Ghost镜像安装,启用USB设备支持,设置共享目录)

    由于某些软件只有windows版本,于是只好安装个虚拟机win7 /**************************安装*************************************/ ...

  8. 最新深度技术GHOST XP系统旗舰增强版 V2016年

    来自系统妈:http://www.xitongma.com 深度技术GHOST xp系统旗舰增强版 V2016年 系统概述 深度技术ghost xp系统旗舰增强版集合微软JAVA虚拟机IE插件,增强浏 ...

  9. 深度技术GHOST WIN7系统32.64位j极速安装版 V2016年

    系统来自系统妈:http://www.xitongma.com 深度技术GHOST win7系统64位j极速安装版 V2016年3月 系统概述 深度技术ghost win7系统64位j极速安装版  版 ...

随机推荐

  1. 中小型企业SaaS行业将崛起于新十年

    2020开始的新十年,国内中小型企业SaaS市场将迎来蓬勃生机,四大助推器已经就绪 第一,云服务打好底座: 随着阿里云.腾讯云乃至华为云的蓬勃发展,基础设施的不断完善,为中小型Saas企业的发展,提供 ...

  2. day02 MySQL基本操作

    day02 MySQL基本操作 昨日内容回顾 数据库演变史 1.纯文件阶段 2.目录规范 3.单机游戏 4.联网游戏 # 数据库就是一款帮助我们管理数据的程序 软件开发架构及数据库本质 cs架构与bs ...

  3. Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null objec

    遇到这个一场折腾了1个小时, 这是系统在解析XML的时候出错, 最后费了好大的劲才发现 XML文件中,<View>  写成小写的 <view> 了. 崩溃啊.......... ...

  4. Spring DM 2.0 环境配置 解决Log4j问题

    搭建 spring dm 2.0 环境出的问题 log4j 的问题解决办法是 一.引入SpringDM2.0的Bundle,最后完成如下图所示:注意:要引入slf4j.api.slf4j.log4j. ...

  5. 6.Vue.js-条件与循环

    条件判断 v-if 条件判断使用 v-if 指令: <div id="app"> <p v-if="seen">现在你看到我了</ ...

  6. Redis cluster 集群报错合集

    目录 一.连接集群操作报错(error)MOVED 二.集群关闭后重启报错 三.Redis (error) NOAUTH Authentication required 四.Redis集群使用中突然挂 ...

  7. 解放双手,自动生成“x.set(y.get)”,搞定vo2dto转换

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 给你机会,你也不中用啊 这些年从事编程开发以来,我好像发现了大部分研发那些不愿意干的 ...

  8. 【论文笔记】SamWalker: Social Recommendation with Informative Sampling Strategy

    SamWalker: Social Recommendation with Informative Sampling Strategy Authors: Jiawei Chen, Can Wang, ...

  9. [BUUCTF]PWN——pwnable_orw

    pwnable_orw 附件 步骤: 例行检查,32位程序,开启了canary 本地运行一下程序,看看大概的情况,提示我们输入shellcode 32位ida载入,检索字符串,没看见什么可以直接利用的 ...

  10. 设置项目的日程排定方式(Project)

    <Project2016 企业项目管理实践>张会斌 董方好 编著 [项目]>[属性]>[项目信息]>[日程排定方法]>选取: 默认项是[项目开始日期]. 这两位是干 ...