Prime Gift CodeForces - 912E (中途相遇)
大意:求素因子只含给定素数的第k大数
先二分答案转为判定x是第几大, 然后分两块合并即可, 按奇偶分块可以优化一下常数
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back using namespace std;
typedef long long ll; const int N = 2e5+10;
int a[N], b[N], f[N], n, m;
ll k;
vector<ll> s[2]; ll calc(ll x) {
ll ans = 0;
int now = 0;
PER(i,0,s[0].size()-1) {
while (now<s[1].size()&&s[1][now]<=x/s[0][i]) ++now;
ans += now;
}
return ans;
} void dfs(int d, int cur, ll now) {
s[d].pb(now);
REP(i,cur,*f) if (now<=1e18/f[i]) dfs(d,i,now*f[i]);
} int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
sort(a+1,a+1+n);
scanf("%lld", &k);
REP(i,1,n) if (i&1) f[++*f] = a[i];
dfs(0,1,1), *f = 0;
REP(i,1,n) if (i&1^1) f[++*f] = a[i];
dfs(1,1,1);
sort(s[0].begin(),s[0].end());
sort(s[1].begin(),s[1].end());
ll l = 1, r = 1e18, ans;
while (l<=r) {
int mid = (l+r)/2;
if (calc(mid)>=k) ans = mid, r = mid-1;
else l = mid+1;
}
printf("%lld\n", ans);
}
Prime Gift CodeForces - 912E (中途相遇)的更多相关文章
- Number Clicker CodeForces - 995E (中途相遇)
链接 大意: 给定模数$p$, 假设当前在$x$, 则可以走到$x+1$, $x+p-1$, $x^{p-2}$ (mod p), 求任意一条从u到v不超过200步的路径 官方题解给了两个做法, 一个 ...
- Codeforces 912E - Prime Gift
912E - Prime Gift 思路: 折半枚举+二分check 将素数分成两个集合(最好按奇偶位置来,保证两集合个数相近),这样每个集合枚举出来的小于1e18的积个数小于1e6. 然后二分答案, ...
- Codeforces 912E Prime Gift(预处理 + 双指针 + 二分答案)
题目链接 Prime Gift 题意 给定一个素数集合,求第k小的数,满足这个数的所有质因子集合为给定的集合的子集. 保证答案不超过$10^{18}$ 考虑二分答案. 根据折半的思想,首先我们把这个 ...
- Codeforces H. Prime Gift(折半枚举二分)
题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- Codeforces 912 E.Prime Gift (折半枚举、二分)
题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...
- uva 6757 Cup of Cowards(中途相遇法,貌似)
uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...
- LA 2965 Jurassic Remains (中途相遇法)
Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- linux常用命令(替换)
1. vi 模式下的替换命令: s 表示替换(substitute),g表示全局搜索(global search) :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vi ...
- git常用命令3
一. Git 常用命令速查 git branch 查看本地所有分支git status 查看当前状态git commit 提交git branch -a 查看所有的分支git branch -r 查看 ...
- web测试项目总结
一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号.禁止直接输入特殊字符时,使 ...
- [转载]LinkButton跳转页面及传递参数
在DataList中使用LinkButton按钮(LinkButtonDelete),该按钮用于链接跳转到删除页面.在模板中双击该按钮,跳转到.cs页面.问题是我们如何获得该条信息的ID,如果不知道I ...
- Linux学习笔记之Linux Centos关闭防火墙
# Centos6.x /etc/init.d/iptables stop chkconfig iptables off sed -i 's/SELINUX=enforcing/SELINUX=dis ...
- 动态规划(Dynamic Programming)
introduction 大部分书籍介绍"动态规划"时,都会从"菲波纳切数列"讲起. 菲波纳切数列 递归解法 C++ 代码如下 unsigned long in ...
- C_Learning(3)
/ 结构体 / 声明结构体类型的一般形式: struct 结构体名[--表示的是这个结构体的类型] { 成员列表 }; [不要漏掉这个";"] / 声明结构可以放在main函 ...
- 阿里druid连接池
1.加入jar包, 下载地址:druid-1.1.0.zip 2.ApplicationContext.xml <!-- druid阿里云连接池 --> <bean name=&qu ...
- 20145122《JAVA开发环境的熟悉》实验报告
package fib; public class fibonaci { public static void main(String[] args) { Fibonaci(20); } public ...
- poj 2369 Permutations - 数论
We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Les ...