链接

大意:求素因子只含给定素数的第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 (中途相遇)的更多相关文章

  1. Number Clicker CodeForces - 995E (中途相遇)

    链接 大意: 给定模数$p$, 假设当前在$x$, 则可以走到$x+1$, $x+p-1$, $x^{p-2}$ (mod p), 求任意一条从u到v不超过200步的路径 官方题解给了两个做法, 一个 ...

  2. Codeforces 912E - Prime Gift

    912E - Prime Gift 思路: 折半枚举+二分check 将素数分成两个集合(最好按奇偶位置来,保证两集合个数相近),这样每个集合枚举出来的小于1e18的积个数小于1e6. 然后二分答案, ...

  3. Codeforces 912E Prime Gift(预处理 + 双指针 + 二分答案)

    题目链接 Prime Gift 题意  给定一个素数集合,求第k小的数,满足这个数的所有质因子集合为给定的集合的子集. 保证答案不超过$10^{18}$ 考虑二分答案. 根据折半的思想,首先我们把这个 ...

  4. Codeforces H. Prime Gift(折半枚举二分)

    题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...

  5. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  6. Codeforces 912 E.Prime Gift (折半枚举、二分)

    题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...

  7. uva 6757 Cup of Cowards(中途相遇法,貌似)

    uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...

  8. LA 2965 Jurassic Remains (中途相遇法)

    Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...

  9. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

随机推荐

  1. yum hosts

    67.219.148.138 mirrorlist.centos.org202.38.97.230 ftp.sjtu.edu.cn202.121.199.235 mirrors.shu.edu.cn2 ...

  2. Ubuntu系统下Jenkins的git构建基本方法

    上一博文讲到了本地脚本的构建方法. 本篇博文主要讲“Ubuntu系统下Jenkins的git构建基本方法”. 点击保存后即可完成简单的构建. 构建触发器 这个触发器是决定什么时候触发构建,可以设置为定 ...

  3. Advapi32.dll--介绍

    https://blog.csdn.net/zhoujielun123456/article/details/50338147 使用方法详见:OpsTotalService

  4. Vue 父组件循环使用refs调用子组件方法出现undefined的问题

    Vue 父组件循环使用refs调用子组件方法出现undefined的问题 1. 背景 最近前端项目遇到一个问题,我在父组件中使用了两个相同的子组件child,分别设置ref为add和update.其中 ...

  5. visual studio扩展插件Visual Assist x给代码插入注释模板(转载)

    转载:http://www.cnblogs.com/xiongmao-cpp/p/5196555.html Visual Assist 是由Whole Tomato公司为Microsoft Visua ...

  6. VC++开机自动启动程序的几种方法 (转载)

    转载:http://blog.csdn.net/zhazhiqiang/article/details/51909703 很多监控软件要求软件能够在系统重新启动后不用用户去点击图标启动项目,而是直接能 ...

  7. 多线程中的信号机制--signwait()函数【转】

    本文转载自:http://blog.csdn.net/yusiguyuan/article/details/14237277 在Linux的多线程中使用信号机制,与在进程中使用信号机制有着根本的区别, ...

  8. boot sector FAT

  9. MacBook PRO蓝牙无法搜索设备

    背景 经常把MacBook合上盖子就塞进包里,用时打开盖子就继续操作,偶尔会出现刚刚还在用的罗技蓝牙鼠标,重新打开笔记本后就连接不上了,而且也无法搜索到周边的蓝牙设备. 解决方案 快捷键:Option ...

  10. 矩阵二分快速幂优化dp动态规划

    矩阵快速幂代码: int n; // 所有矩阵都是 n * n 的矩阵 struct matrix { int a[100][100]; }; matrix matrix_mul(matrix A, ...