北方多校十四场_Easy Number_二分+容斥原理
来源:互联网 发布:java什么是反射 编辑:程序博客网 时间:2024/04/29 00:37
题目链接:https://nanti.jisuanke.com/t/15727
容斥原理公式:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 12;const LL inf = 1e17;LL A[maxn];int T;int N, K;LL res;LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a%b);}// 容斥原理 dfs// it该层处理哪个数,now已有最小公倍数,ub上限// f这一项的正负号,这时的now是不是初始默认的那个1void dfs(int it, LL now, LL ub, int f, bool ori){if(now > ub) return;if(it == N){if(ori) return;res += f * ub / now;return;}dfs(it+1, now, ub, f, ori);dfs(it+1, now/gcd(now, A[it])*A[it], ub, -f, 0);}bool Judge(LL x){// 容斥原理,可别忘了初始化 resres = 0;dfs(0, 1, x, -1, 1);if(res >= K) return true;return false;}int main(){scanf("%d", &T);while(T--){scanf("%d %d", &N, &K);for(int i= 0; i< N; i++)scanf("%lld", A+i);LL lb = 0, ub = inf;while(lb <= ub){LL mid = (ub - lb) / 2 + lb;if(Judge(mid)) ub = mid - 1;else lb = mid + 1;}cout << ub + 1 << endl;}return 0;}
阅读全文
0 0
- 北方多校十四场_Easy Number_二分+容斥原理
- 多校第一场 1010 hdu 5297 Y sequence(容斥+二分)
- HDU3388(二分+容斥原理)
- hdu3388Coprime 二分+容斥原理
- 二分+容斥原理-HDU3388
- hdu 6106 Classes 2017多校第六场1011签到题 容斥原理
- 容斥原理(二分+排序)
- hdu 3388二分 容斥原理
- hdu3388 Coprime 二分+容斥原理
- POJ 2773 二分 +容斥原理
- poj 2773 容斥原理+二分
- Coprime (二分+容斥原理)
- poj-2773(数论+容斥原理+二分)
- 多校联合第五场北京正常大学BNU 1002 Lucky Numbers(找规律or容斥原理?)
- 2017多校第二场1009(容斥)
- 北方大学多校训练第12场C题
- SOJ 3191 Free square 容斥原理+二分
- POJ 2773 Happy 2006 二分+容斥原理
- 淘淘商城系列——使用Spring来管理Redis单机版和集群版
- 会议室预约系统实例分析
- 创建线程
- 内存问题的排查工具和方法– Clang的AddressSanitizer
- 延时执行
- 北方多校十四场_Easy Number_二分+容斥原理
- ZJCoj qwb与支教 ( 容斥+二分
- 计算行列式(C++)
- Java学习笔记---枚举
- MySQL CPU 使用率高的原因和解决方法(来自aliyun官方文档)
- 应用数据管理工具类
- 队列组处理网络图片合成/水印
- Autoreleasepool
- Leetcode Week14