HDU 3641 Treasure Hunting(阶乘素因子分解+二分)
题意:
求最小的 ( x! ) = 0 mod (a1^b1*a2^b2...an^bn)
分析:
首先吧a1~an进行素因子分解,然后统计下每一个质因子的指数。因为随着x的增大,质因子的个数是逐渐添加的
因此我们能够二分x。对x!进行素因子分解推断是否满足条件。然后求出最小的就能够了。
代码例如以下:
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- const int maxn = 110;
- typedef long long LL;
- bool vis[maxn];
- int p[maxn],cnt;
- LL a[maxn];
- LL b[maxn];
- LL num[maxn];
- void init(){
- cnt = 0;
- memset(vis,0,sizeof(vis));
- for(int i=2;i<maxn;i++){
- if(!vis[i]){
- p[cnt++]=i;
- for(int j=i+i;j<maxn;j+=i)
- vis[j]=1;
- }
- }
- }
- LL get_num(LL x,int pri){
- if(x<pri) return 0;
- return get_num(x/pri,pri)+(LL)x/pri;
- }
- bool check(LL x){
- for(int i=0;i<cnt;i++){
- if(get_num(x,p[i])<num[p[i]])
- return false;
- }
- return true;
- }
- int main()
- {
- init();
- int t,n;
- scanf("%d",&t);
- while(t--){
- scanf("%d",&n);
- memset(num,0,sizeof(num));
- for(int i=0;i<n;i++){
- scanf("%I64d%I64d",a+i,b+i);
- int tmp = a[i];
- for(int j=0;p[j]*p[j]<=tmp&&j<cnt;j++){
- if(tmp%p[j]==0){
- LL tot=0;
- while(tmp%p[j]==0) tmp=tmp/p[j],tot++;
- num[p[j]]+=tot*b[i];
- }
- }
- if(tmp>1) num[tmp]+=b[i];
- }
- LL ans = 0;
- for(int i=0;i<maxn;i++)
- ans=max(ans,(LL)i*num[i]);
- LL l=0,r=ans;
- while(l<=r){
- LL mid=(l+r)>>1;
- if(check(mid)) r=mid-1;
- else l=mid+1;
- }
- printf("%I64d\n",l);
- }
- return 0;
- }
- /*
- 111
- 6
- 6 1000000000000
- 15 1000000000000
- 13 1000000000000
- 7 1000000000000
- 2 1000000000000
- 3 1000000000000
- */
HDU 3641 Treasure Hunting(阶乘素因子分解+二分)的更多相关文章
- hdu 3641 Treasure Hunting 强大的二分
/** 大意:给定一组ai,bi . m = a1^b1 *a2^b2 * a3^ b3 * a4^b4*...*ai^bi 求最小的x!%m =0 思路: 将ai 质因子分解,若是x!%m=0 那么 ...
- HDU 3468 Treasure Hunting(BFS+网络流之最大流)
题目地址:HDU 3468 这道题的关键在于能想到用网络流.然后还要想到用bfs来标记最短路中的点. 首先标记方法是,对每个集合点跑一次bfs,记录全部点到该点的最短距离.然后对于随意一对起始点来说, ...
- 【网络流】 HDU 3468 Treasure Hunting
题意: A-Z&&a-z 表示 集结点 从A点出发经过 最短步数 走到下一个集结点(A的下一个集结点为B ,Z的下一个集结点为a) 的路上遇到金子(*)则能够捡走(一个点仅仅能捡一次) ...
- [Codeforces 1201D]Treasure Hunting(DP)
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...
- Codeforces Round #577 (Div. 2) D. Treasure Hunting
Codeforces Round #577 (Div. 2) D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...
- hdu 3641 数论 二分求符合条件的最小值数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...
- hdu3468 Treasure Hunting 二分匹配
//给一个n*m的图 //.表示空白地 //*表示有黄金 //#表示墙 //一个人须要依照A...Z..a..z的顺序以最短路径走到下一个 //每次仅仅能在他的路线上经过的地方取一块黄金 //问最多能 ...
- Treasure Hunting HDU - 3468
题意: 输入一个n行m列的图 每次按字母顺序走最短路, 从一个字母走到下一个字母的过程中,只能拿走一个金子,求走完当前图中所有的字母后能拿到的金子的最大值 解析: bfs求最短路 对于一个金子如果 d ...
- (hdu)5652 India and China Origins 二分+dfs
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5652 Problem Description A long time ago there ...
随机推荐
- 解决:“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i38...
编译android源码,找不到g++.通过apt-get下载时候,总是提示“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)” 的盘片插入 ...
- Kruskal-Wallis Test and Friedman test
- Weinre - 远程调试工具
Weinre 代表Web Inspector Remote,是一种远程调试工具.借助于网络,可以在PC上直接调试运行在移动设备上的远程页面,中文意思是远程Web检查器,有了Wei ...
- 使用after伪类清除浮动
使用after伪类清除浮动 .department li:after{ content:"."; height:0; visibility:hidden; display:bloc ...
- 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. ...
- 查询最小未使用ID的SQL查询
--每个都加一,以此来找出最小的未用ID SELECT Min(T1.ID)+1 FROM dbo.TestTable T1 -- 不用查询已经存在的ID WHERE (T1.ID+1) NOT IN ...
- 自学Xpath的几个例子
Xpath可以对XML文件中的信息进行查找,并对XML文件树形结构进行遍历.详细语法请转:http://www.w3school.com.cn/xpath/index.asp 例子:利用在JavaSc ...
- 让ie支持placeholder属性,一段js搞定
placeholder属性真的是超级好用的新属性,可惜,只有新版浏览器才支持,为了写出输入框贴心提示,老方法就是加span标签覆盖,营造出placeholder提示的感觉,现在安利一款好用的js,好用 ...
- asp.net BulletedList样式修改 css
首先编写一段简单的css脚本 然后呢,在asp:BulletedList中通过 CssClass ="style1"将样式作用到控件上.看看运行效果 注意到上下边框的颜色分别是红色 ...
- 一个证书多次使用-导出p12文件
在苹果开发者网站申请的证书,是授权mac设备的开发或者发布的证书,这意味着一个设备对应一个证书,但是99美元账号只允许生成3个发布证书,两个开发证书,这满足不了多mac设备的使用,使用p12文件可以解 ...