题目链接:

pid=3641">传送门

题意:

求最小的 ( x! ) = 0 mod (a1^b1*a2^b2...an^bn)

分析:

首先吧a1~an进行素因子分解,然后统计下每一个质因子的指数。因为随着x的增大,质因子的个数是逐渐添加的

因此我们能够二分x。对x!进行素因子分解推断是否满足条件。然后求出最小的就能够了。

代码例如以下:

  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cstdio>
  5. using namespace std;
  6. const int maxn = 110;
  7. typedef long long LL;
  8. bool vis[maxn];
  9. int p[maxn],cnt;
  10. LL a[maxn];
  11. LL b[maxn];
  12. LL num[maxn];
  13.  
  14. void init(){
  15. cnt = 0;
  16. memset(vis,0,sizeof(vis));
  17. for(int i=2;i<maxn;i++){
  18. if(!vis[i]){
  19. p[cnt++]=i;
  20. for(int j=i+i;j<maxn;j+=i)
  21. vis[j]=1;
  22. }
  23. }
  24. }
  25.  
  26. LL get_num(LL x,int pri){
  27. if(x<pri) return 0;
  28. return get_num(x/pri,pri)+(LL)x/pri;
  29. }
  30.  
  31. bool check(LL x){
  32. for(int i=0;i<cnt;i++){
  33. if(get_num(x,p[i])<num[p[i]])
  34. return false;
  35. }
  36. return true;
  37. }
  38.  
  39. int main()
  40. {
  41. init();
  42. int t,n;
  43. scanf("%d",&t);
  44. while(t--){
  45. scanf("%d",&n);
  46. memset(num,0,sizeof(num));
  47. for(int i=0;i<n;i++){
  48. scanf("%I64d%I64d",a+i,b+i);
  49. int tmp = a[i];
  50. for(int j=0;p[j]*p[j]<=tmp&&j<cnt;j++){
  51. if(tmp%p[j]==0){
  52. LL tot=0;
  53. while(tmp%p[j]==0) tmp=tmp/p[j],tot++;
  54. num[p[j]]+=tot*b[i];
  55. }
  56. }
  57. if(tmp>1) num[tmp]+=b[i];
  58. }
  59. LL ans = 0;
  60. for(int i=0;i<maxn;i++)
  61. ans=max(ans,(LL)i*num[i]);
  62. LL l=0,r=ans;
  63. while(l<=r){
  64. LL mid=(l+r)>>1;
  65. if(check(mid)) r=mid-1;
  66. else l=mid+1;
  67. }
  68. printf("%I64d\n",l);
  69. }
  70. return 0;
  71. }
  72. /*
  73. 111
  74. 6
  75. 6 1000000000000
  76. 15 1000000000000
  77. 13 1000000000000
  78. 7 1000000000000
  79. 2 1000000000000
  80. 3 1000000000000
  81. */

HDU 3641 Treasure Hunting(阶乘素因子分解+二分)的更多相关文章

  1. hdu 3641 Treasure Hunting 强大的二分

    /** 大意:给定一组ai,bi . m = a1^b1 *a2^b2 * a3^ b3 * a4^b4*...*ai^bi 求最小的x!%m =0 思路: 将ai 质因子分解,若是x!%m=0 那么 ...

  2. HDU 3468 Treasure Hunting(BFS+网络流之最大流)

    题目地址:HDU 3468 这道题的关键在于能想到用网络流.然后还要想到用bfs来标记最短路中的点. 首先标记方法是,对每个集合点跑一次bfs,记录全部点到该点的最短距离.然后对于随意一对起始点来说, ...

  3. 【网络流】 HDU 3468 Treasure Hunting

    题意: A-Z&&a-z 表示 集结点 从A点出发经过 最短步数 走到下一个集结点(A的下一个集结点为B ,Z的下一个集结点为a) 的路上遇到金子(*)则能够捡走(一个点仅仅能捡一次) ...

  4. [Codeforces 1201D]Treasure Hunting(DP)

    [Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...

  5. Codeforces Round #577 (Div. 2) D. Treasure Hunting

    Codeforces Round #577 (Div. 2)  D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...

  6. hdu 3641 数论 二分求符合条件的最小值数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...

  7. hdu3468 Treasure Hunting 二分匹配

    //给一个n*m的图 //.表示空白地 //*表示有黄金 //#表示墙 //一个人须要依照A...Z..a..z的顺序以最短路径走到下一个 //每次仅仅能在他的路线上经过的地方取一块黄金 //问最多能 ...

  8. Treasure Hunting HDU - 3468

    题意: 输入一个n行m列的图 每次按字母顺序走最短路, 从一个字母走到下一个字母的过程中,只能拿走一个金子,求走完当前图中所有的字母后能拿到的金子的最大值 解析: bfs求最短路 对于一个金子如果 d ...

  9. (hdu)5652 India and China Origins 二分+dfs

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5652 Problem Description A long time ago there ...

随机推荐

  1. 解决:“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i38...

    编译android源码,找不到g++.通过apt-get下载时候,总是提示“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)” 的盘片插入 ...

  2. Kruskal-Wallis Test and Friedman test

  3. Weinre - 远程调试工具

              Weinre  代表Web Inspector Remote,是一种远程调试工具.借助于网络,可以在PC上直接调试运行在移动设备上的远程页面,中文意思是远程Web检查器,有了Wei ...

  4. 使用after伪类清除浮动

    使用after伪类清除浮动 .department li:after{ content:"."; height:0; visibility:hidden; display:bloc ...

  5. atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform

    atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform 1. Absoluti 布局(经常使用) 1 2. ...

  6. 查询最小未使用ID的SQL查询

    --每个都加一,以此来找出最小的未用ID SELECT Min(T1.ID)+1 FROM dbo.TestTable T1 -- 不用查询已经存在的ID WHERE (T1.ID+1) NOT IN ...

  7. 自学Xpath的几个例子

    Xpath可以对XML文件中的信息进行查找,并对XML文件树形结构进行遍历.详细语法请转:http://www.w3school.com.cn/xpath/index.asp 例子:利用在JavaSc ...

  8. 让ie支持placeholder属性,一段js搞定

    placeholder属性真的是超级好用的新属性,可惜,只有新版浏览器才支持,为了写出输入框贴心提示,老方法就是加span标签覆盖,营造出placeholder提示的感觉,现在安利一款好用的js,好用 ...

  9. asp.net BulletedList样式修改 css

    首先编写一段简单的css脚本 然后呢,在asp:BulletedList中通过 CssClass ="style1"将样式作用到控件上.看看运行效果 注意到上下边框的颜色分别是红色 ...

  10. 一个证书多次使用-导出p12文件

    在苹果开发者网站申请的证书,是授权mac设备的开发或者发布的证书,这意味着一个设备对应一个证书,但是99美元账号只允许生成3个发布证书,两个开发证书,这满足不了多mac设备的使用,使用p12文件可以解 ...