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 ...
随机推荐
- python import win32clipboard 报错DLL load failed: %1 不是有效的 Win32 应用程序。
在python中引入win32clipboard时报错,DLL load failed: %1 不是有效的 Win32 应用程序 >>> import win32clipboardT ...
- linux常用命令(替换)
1. vi 模式下的替换命令: s 表示替换(substitute),g表示全局搜索(global search) :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vi ...
- Linux服务器---使用mysql
使用mysql 1.登录,可以用密码登录,也可以不用密码登录.命令格式“mysql –u 用户名 –p 密码” [root@localhost src]# mysql -u root –p / ...
- svn忽略目录,svn忽略app目录add toignore list,避免每次更新很多app的内容下来导出到本地很麻烦
svn忽略目录,svn忽略app目录add toignore list,避免每次更新很多app的内容下来导出到本地很麻烦 ------------------------------ 本人微信公众帐号 ...
- ACM题目————Face The Right Way
Description Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing ...
- Python Web学习笔记之Python多线程基础
多线程理解 多线程是多个任务同时运行的一种方式.比如一个循环中,每个循环看做一个任务,我们希望第一次循环运行还没结束时,就可以开始第二次循环,用这种方式来节省时间. python中这种同时运行的目的是 ...
- poj 2773 Happy 2006 - 二分答案 - 容斥原理
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11161 Accepted: 3893 Description Two ...
- MIME协议(详解范例)
转载一:http://blog.csdn.net/bripengandre/article/details/2192982 转载二:http://blog.csdn.net/flfna/article ...
- gensim工具[学习笔记]
平台信息:PC:ubuntu18.04.i5.anaconda2.cuda9.0.cudnn7.0.5.tensorflow1.10.GTX1060 一.将copy_train.csv文件的内容进行分 ...
- C# 获取SQL Server所有的数据库名称
参考文章:http://www.cnblogs.com/Abel_cn/archive/2008/12/09/1351425.html http://blog.csdn.net/friendan/ar ...