Harry Potter and the Hide Story

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2809    Accepted Submission(s): 715

Problem Description
iSea is tired of writing the story of Harry Potter, so, lucky you, solving the following problem is enough.
 
Input
The first line contains a single integer T, indicating the number of test cases.
Each test case contains two integers, N and K.

Technical Specification

1. 1 <= T <= 500
2. 1 <= K <= 1 000 000 000 000 00
3. 1 <= N <= 1 000 000 000 000 000 000
 
Output
For
each test case, output the case number first, then the answer, if the
answer is bigger than 9 223 372 036 854 775 807, output “inf” (without
quote).
 
Sample Input
2
2 2
10 10
 
Sample Output
Case 1: 1
Case 2: 2
 思路:素数分解;
当K = 1的时候肯定输出inf;我们将n分解成素数的乘积,那么我们需要找m!分解后含有这些素数的个数cnt[pi],那么最高次就是min(cnt[pi]/cnt1[pi]);cnt1[pi]为n中pi的个数。
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<queue>
5 #include<set>
6 #include<math.h>
7 #include<string.h>
8 using namespace std;
9 typedef unsigned long long LL;
10 bool prime[10000015];
11 LL ans[1000000];
12 LL prime_table[10000];
13 LL pr_cnt[10000];
14 LL pr_cn[10000];
15 LL slove(LL n,LL m,int cn);
16 int main(void)
17 {
18 int T;
19 scanf("%d",&T);
20 int i,j;
21 for(i = 2; i < 10000; i++)
22 {
23 if(!prime[i])
24 {
25 for(j = i; (i*j) <= 10000010; j++)
26 {
27 prime[i*j] = true;
28 }
29 }
30 }
31 int cn = 0;
32 for(i = 2; i < 10000010; i++)
33 if(!prime[i])ans[cn++] = i;
34 int __ca = 0;
35 while(T--)
36 {
37 LL n,m;
38 __ca++;
39 scanf("%llu %llu",&m,&n);
40 printf("Case %d: ",__ca);
41 if(n == 1)
42 printf("inf\n");
43 else
44 {
45 printf("%llu\n",slove(n,m,cn));
46 }
47 }
48 return 0;
49 }
50 LL slove(LL n,LL m,int cn)
51 {
52 int bn = 0;
53 int f = 0;
54 bool flag = false ;
55 memset(pr_cnt,0,sizeof(pr_cnt));
56 memset(pr_cn,0,sizeof(pr_cn));
57 while(n>1)
58 {
59 while(n%ans[f]==0)
60 {
61 if(!flag)
62 {
63 flag = true;
64 bn++;
65 prime_table[bn] = ans[f];
66 }
67 pr_cnt[bn]++;
68 n/=ans[f];
69 }
70 f++;
71 flag = false;
72 if((LL)ans[f]*(LL)ans[f] > n)
73 break;
74 }
75 if(n > 1)
76 {
77 bn++;
78 prime_table[bn] = n;
79 pr_cnt[bn]++;
80 }//printf("%d\n",n);
81 LL maxx = -1;
82 for(int i = 1; i <= bn; i++)
83 { //printf("%llu\n",prime_table[i]);
84 LL v = m;
85 while(v)
86 {
87 v/=(LL)prime_table[i];
88 pr_cn[i]+=v;
89 }
90 if(maxx == -1)
91 {
92 maxx = (LL)pr_cn[i]/(LL)pr_cnt[i];
93 }
94 else
95 maxx = min((LL)pr_cn[i]/(LL)pr_cnt[i],maxx);
96 }
97 return maxx;
98 }

Harry Potter and the Hide Story(hdu3988)的更多相关文章

  1. HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)

    Harry Potter and the Hide Story Problem Description iSea is tired of writing the story of Harry Pott ...

  2. HDU3988-Harry Potter and the Hide Story(数论-质因数分解)

    Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 ...

  3. HDU 3987 Harry Potter and the Forbidden Forest(边权放大法+最小割)

    Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/ ...

  4. View and Data API Tips: Hide elements in viewer completely

    By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...

  5. jquery的show/hide/toggle详解

    通过阅读源码我们发现show,hide,toggle调用了showHide和isHidden这2个方法,所以我们要搞明白原理必须先看一下这2个方法. jQuery.fn.extend({ ...... ...

  6. Jquery:hide一个元素,需要注意的问题(offset)

    $(".load_more").css('display','none'); 或 $(that.more).find("strong").hide(); 需要注 ...

  7. jquery的hide()和show()

    jquery用hide()和show()函数来控制html元素的显示和隐藏. hide()和show()都可以带参数的,hide(1000)表示隐藏所需的时间为1秒.此外还可以用slow,fast参数 ...

  8. JS——树形导航菜单(html的ul嵌套,jQuery的css(),show(),hide(),index()等方法)

    必备工具:jquery库文件.我这里用的是1.4版本的. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  9. [转]Hide or Remove jquery ui tab based on condition

    本文转自:http://stackoverflow.com/questions/19132970/hide-or-remove-jquery-ui-tab-based-on-condition 问: ...

随机推荐

  1. 普通用户iptables规则持久化,开机自动恢复

    本文档对于docker环境下并不适用,docker环境的iptables持久化请参考https://www.cnblogs.com/wiseo/p/15000745.html 添加iptables规则 ...

  2. SM 国密算法踩坑指南

    各位,好久不见~ 最近接手网联的国密改造项目,由于对国密算法比较陌生,前期碰到了一系列国密算法加解密的问题. 所以这次总结一下,分享这个过程遇到的问题,希望帮到大家. 国密 什么是国密算法? 国密就是 ...

  3. java Random()用法

    1.random.nextInt() random.nextIn()的作用是随机生成一个int类型,因为int 的取值范围是 -2147483648--2147483647 ,所以生成的数也是处于这个 ...

  4. 日常Java 2021/11/2

    Java提供了一种对象序列化的机制,该机制中,一个对象可以被表示为一个字节序列,该字节序列包括该对象的数据.有关对象的类型的信息和存储在对象中数据的类型.将序列化对象写入文件之后,可以从文件中读取出来 ...

  5. 一条查询SQL查询语句的执行原理

    先熟悉一下浅而易懂SQL执行的流程图SQL查询过程七步曲 1.查询SQL发送请求 客户端将查询sql按照mysql通信协议传输到服务端.服务端接受到请求后,服务端单起一个线程执行sql 2.判断是否为 ...

  6. 一份不错的Java就业指导

    想要成为合格的Java程序员或工程师到底需要具备哪些专业技能,面试者在面试之前到底需要准备哪些东西呢? 本文陈列的这些内容既可以作为个人简历中的内容,也可以作为面试的时候跟面试官聊的东西,你可以把这些 ...

  7. Output of C++ Program | Set 2

    Predict the output of below C++ programs. Question 1 1 #include<iostream> 2 using namespace st ...

  8. 【Linux】【Services】【SaaS】Docker+kubernetes(7. 安装Docker私有镜像仓库)

    1. 简介 1.1. 自己做个私有镜像,方便上传和下载,我也在docker官网注册了一个账号,做好的镜像可以传上去 1.2. Redhat自带私有镜像的功能,需要安装包,这是howto: https: ...

  9. 部署应用程序到Tomcat的webapps目录

    一.方法如下 1.通过MyEclipse上方工具栏Manage Deployments,依次选择项目和服务器: 2.通过右击项目Export,生成war包到webapps中: 3.复制项目WebRoo ...

  10. ssm动态查询向前台传json

    1.数据协议层 public User selectById(Integer id);//通过id值查询用户 2.数据层 <select id="selectById" re ...