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 ...
随机推荐
- 03:requests与BeautifulSoup结合爬取网页数据应用
1.1 爬虫相关模块命令回顾 1.requests模块 1. pip install requests 2. response = requests.get('http://www.baidu.com ...
- Win7系统中如何查看当前文件被哪一个程序占用了
https://superuser.com/questions/117902/find-out-which-process-is-locking-a-file-or-folder-in-windows ...
- Python 逗号的几种作用
转自http://blog.csdn.net/liuzx32/article/details/7831247 最近研究Python 遇到个逗号的问题 一直没弄明白 今天总算搞清楚了 1.逗号在参数传 ...
- Cent OS 常用配置命令
1.ifconfig #查看网络接口状态 2.ifconfig –a #查看主机所有接口的情况 3.ifconfig eth0 192.168.1.106 netmask 255.255.255 ...
- json库的编译方法和vs2010中导入第三方库的方法
json库的编译方法和vs2010中导入第三方库的方法 一.去相应官网下载json.cpp文件 Jsoncpp下载:https://sourceforge.net/projects/jsoncpp/ ...
- Axure RP 8.0 Licence
新版本:(比如 Axure RP 8.0.0 3319)Licensee:米 业成 (STUDENT)Key:nFmqBBvEqdvbiUjy8NZiyWiRSg3yO+PtZ8c9wdwxWse4W ...
- pandas 设置单元格的值
import pandas as pd import pickle import numpy as np dates = pd.date_range() df = pd.DataFrame(np.ar ...
- django 数据库同步
python manage.py makemigrations python manage.py migrate
- [ogre]ogre::Animation
参考:http://blog.csdn.net/leonwei/article/details/5819248 http://blog.csdn.net/debugconsole/article/de ...
- 2018年全国多校算法寒假训练营练习比赛(第一场)D N阶汉诺塔变形
https://www.nowcoder.com/acm/contest/67/D 思路: 先手动模拟一下过程,以下是模拟过程,按顺序表示第几步需要移动的盘标号 1 1 2 1 1 2 1 1 3 1 ...