Harry Potter and the Hide Story(hdu3988)
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
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
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).
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)的更多相关文章
- 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 ...
- HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 ...
- HDU 3987 Harry Potter and the Forbidden Forest(边权放大法+最小割)
Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/ ...
- 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 ...
- jquery的show/hide/toggle详解
通过阅读源码我们发现show,hide,toggle调用了showHide和isHidden这2个方法,所以我们要搞明白原理必须先看一下这2个方法. jQuery.fn.extend({ ...... ...
- Jquery:hide一个元素,需要注意的问题(offset)
$(".load_more").css('display','none'); 或 $(that.more).find("strong").hide(); 需要注 ...
- jquery的hide()和show()
jquery用hide()和show()函数来控制html元素的显示和隐藏. hide()和show()都可以带参数的,hide(1000)表示隐藏所需的时间为1秒.此外还可以用slow,fast参数 ...
- JS——树形导航菜单(html的ul嵌套,jQuery的css(),show(),hide(),index()等方法)
必备工具:jquery库文件.我这里用的是1.4版本的. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- [转]Hide or Remove jquery ui tab based on condition
本文转自:http://stackoverflow.com/questions/19132970/hide-or-remove-jquery-ui-tab-based-on-condition 问: ...
随机推荐
- 什么是DDL,DML,DCL
转载自 https://www.2cto.com/database/201610/555167.html DML.DDL.DCL区别 . 总体解释: DML(data manipulation la ...
- 学习java的第二十五天
一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...
- 多人协作解决方案,git flow的使用
简介 Gitflow工作流程围绕项目发布定义了严格的分支模型. 为不同的分支分配了非常明确的角色,并且定义了使用场景和用法.除了用于功能开发的分支,它还使用独立的分支进行发布前的准备.记录以及后期维护 ...
- 【STM32】使用SDIO进行SD卡读写,包含文件管理FatFs(八)-认识内存管理
[STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(一)-初步认识SD卡 [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(二)-了解SD总线,命令的相关介绍 [STM3 ...
- 为Python的web框架编写前端模版的教程
虽然我们跑通了一个最简单的MVC,但是页面效果肯定不会让人满意. 对于复杂的HTML前端页面来说,我们需要一套基础的CSS框架来完成页面布局和基本样式.另外,jQuery作为操作DOM的JavaScr ...
- OSGI 理论知识
下面列出了主要的控制台命令: 表 1. Equinox OSGi 主要的控制台命令表 类别 命令 含义 控制框架 launch 启动框架 shutdown 停止框架 close 关闭.退出框架 exi ...
- 【编程思想】【设计模式】【结构模式Structural】MVC
Python版 https://github.com/faif/python-patterns/blob/master/structural/mvc.py #!/usr/bin/env python ...
- Spring Boot 和 Spring Cloud Feign调用服务及传递参数踩坑记录
背景 :在Spring Cloud Netflix栈中,各个微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.我们可以使用JDK原生的URLConnectio ...
- 使用buffered流结合byte数组,读入文件中的内容,包括中文字符
package com.itcast.demo05.Buffered;import java.io.BufferedInputStream;import java.io.FileInputStream ...
- 【力扣】82. 删除排序链表中的重复元素 II
存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除链表中所有存在数字重复情况的节点,只保留原始链表中 没有重复出现 的数字. 返回同样按升序排列的结果链表. 示例 1: 输入:hea ...