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. 1 #include<stdio.h>
  2. 2 #include<algorithm>
  3. 3 #include<iostream>
  4. 4 #include<queue>
  5. 5 #include<set>
  6. 6 #include<math.h>
  7. 7 #include<string.h>
  8. 8 using namespace std;
  9. 9 typedef unsigned long long LL;
  10. 10 bool prime[10000015];
  11. 11 LL ans[1000000];
  12. 12 LL prime_table[10000];
  13. 13 LL pr_cnt[10000];
  14. 14 LL pr_cn[10000];
  15. 15 LL slove(LL n,LL m,int cn);
  16. 16 int main(void)
  17. 17 {
  18. 18 int T;
  19. 19 scanf("%d",&T);
  20. 20 int i,j;
  21. 21 for(i = 2; i < 10000; i++)
  22. 22 {
  23. 23 if(!prime[i])
  24. 24 {
  25. 25 for(j = i; (i*j) <= 10000010; j++)
  26. 26 {
  27. 27 prime[i*j] = true;
  28. 28 }
  29. 29 }
  30. 30 }
  31. 31 int cn = 0;
  32. 32 for(i = 2; i < 10000010; i++)
  33. 33 if(!prime[i])ans[cn++] = i;
  34. 34 int __ca = 0;
  35. 35 while(T--)
  36. 36 {
  37. 37 LL n,m;
  38. 38 __ca++;
  39. 39 scanf("%llu %llu",&m,&n);
  40. 40 printf("Case %d: ",__ca);
  41. 41 if(n == 1)
  42. 42 printf("inf\n");
  43. 43 else
  44. 44 {
  45. 45 printf("%llu\n",slove(n,m,cn));
  46. 46 }
  47. 47 }
  48. 48 return 0;
  49. 49 }
  50. 50 LL slove(LL n,LL m,int cn)
  51. 51 {
  52. 52 int bn = 0;
  53. 53 int f = 0;
  54. 54 bool flag = false ;
  55. 55 memset(pr_cnt,0,sizeof(pr_cnt));
  56. 56 memset(pr_cn,0,sizeof(pr_cn));
  57. 57 while(n>1)
  58. 58 {
  59. 59 while(n%ans[f]==0)
  60. 60 {
  61. 61 if(!flag)
  62. 62 {
  63. 63 flag = true;
  64. 64 bn++;
  65. 65 prime_table[bn] = ans[f];
  66. 66 }
  67. 67 pr_cnt[bn]++;
  68. 68 n/=ans[f];
  69. 69 }
  70. 70 f++;
  71. 71 flag = false;
  72. 72 if((LL)ans[f]*(LL)ans[f] > n)
  73. 73 break;
  74. 74 }
  75. 75 if(n > 1)
  76. 76 {
  77. 77 bn++;
  78. 78 prime_table[bn] = n;
  79. 79 pr_cnt[bn]++;
  80. 80 }//printf("%d\n",n);
  81. 81 LL maxx = -1;
  82. 82 for(int i = 1; i <= bn; i++)
  83. 83 { //printf("%llu\n",prime_table[i]);
  84. 84 LL v = m;
  85. 85 while(v)
  86. 86 {
  87. 87 v/=(LL)prime_table[i];
  88. 88 pr_cn[i]+=v;
  89. 89 }
  90. 90 if(maxx == -1)
  91. 91 {
  92. 92 maxx = (LL)pr_cn[i]/(LL)pr_cnt[i];
  93. 93 }
  94. 94 else
  95. 95 maxx = min((LL)pr_cn[i]/(LL)pr_cnt[i],maxx);
  96. 96 }
  97. 97 return maxx;
  98. 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. shell 指令

    cat/proc/parttitions df -T pstree ext4 是linux 文件系统

  2. Identity Server 4 从入门到落地(五)—— 使用Ajax访问Web Api

    前面的部分: Identity Server 4 从入门到落地(一)-- 从IdentityServer4.Admin开始 Identity Server 4 从入门到落地(二)-- 理解授权码模式 ...

  3. Shell 管道指令pipe

    目录 管道命令pipe 选取命令 cut.grep cut 取出需要的信息 grep 取出需要行.过滤不需要的行 排序命令 sort.wc.uniq sort 排序 假设三位数,按十位数从小到大,个位 ...

  4. 大数据学习day33----spark13-----1.两种方式管理偏移量并将偏移量写入redis 2. MySQL事务的测试 3.利用MySQL事务实现数据统计的ExactlyOnce(sql语句中出现相同key时如何进行累加(此处时出现相同的单词))4 将数据写入kafka

    1.两种方式管理偏移量并将偏移量写入redis (1)第一种:rdd的形式 一般是使用这种直连的方式,但其缺点是没法调用一些更加高级的api,如窗口操作.如果想更加精确的控制偏移量,就使用这种方式 代 ...

  5. Ecshop 安装

    参考 http://www.68ecshop.com/article-617.html ecshop的安装第一步:下载ecshop网店系统正式版安装包 我们可以来ecshop开发中心的官网(www.6 ...

  6. [学习总结]6、Android异步消息处理机制完全解析,带你从源码的角度彻底理解

    开始进入正题,我们都知道,Android UI是线程不安全的,如果在子线程中尝试进行UI操作,程序就有可能会崩溃.相信大家在日常的工作当中都会经常遇到这个问题,解决的方案应该也是早已烂熟于心,即创建一 ...

  7. tableView和tableViewCell的背景颜色问题

    当在tableView中添加cell数据时,我们会发现原本设置的tableView的背景颜色不见了,这是因为加载cell数据时,tableView的背景颜色被cell数据遮盖住了,此时,可以通过设置c ...

  8. Linux:expr、let、for、while、until、shift、if、case、break、continue、函数、select

    1.expr计算整数变量值 格式 :expr arg 例子:计算(2+3)×4的值 1.分步计算,即先计算2+3,再对其和乘4 s=`expr 2 + 3` expr $s \* 4 2.一步完成计算 ...

  9. jquery:iframe里面的元素怎样触发父窗口元素的事件?

    例如父窗口定义了一个事件. top: $(dom1).bind('topEvent', function(){}); 那么iframe里面的元素怎样触发父窗口dom1的事件呢?这样吗? $(dom1, ...

  10. 莫烦python教程学习笔记——validation_curve用于调参

    # View more python learning tutorial on my Youtube and Youku channel!!! # Youtube video tutorial: ht ...