UVAlive 4683 Find The Number
来源:互联网 发布:大数据怎么快速学 编辑:程序博客网 时间:2024/05/17 05:56
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=14336
题意:给一个含k个数的集合,符合条件的数当且仅当满足被集合中的一个数整除,求最小区间上界x,使得[1,x]内含有n个符合条件的数。
思路:二分答案+dfs容斥,如果用二进制枚举会超时。如果当前的倍数k是由x个数得到的,那么会有(n/k)个数之前会被那x个数单独都统计进去一次,所以是(n/k)*x。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod %100000007int T;int p[15];int m;LL k;LL ans;LL gcd(LL a , LL b){ return (a%b==0)?b:gcd(b,a%b);}void dfs(int now , int num , LL lcm , LL n){ if ( lcm > 1e15 ) return; if ( num & 1 ) ans+=n/lcm*num; else ans-=n/lcm*num; rep(i,now+1,m) dfs( i , num+1 , lcm/gcd(lcm,p[i])*p[i] , n );}int main(){ cin>>T; while(T--) { scanf("%d %lld",&m,&k); rep(i,1,m) scanf("%d",p+i); LL L = 1; LL R = 1e15; LL mid; while(L<R) { ans = 0; mid = (L+R)>>1; rep(i,1,m) dfs(i,1,p[i],mid); if ( ans >= k ) R = mid; else L = mid + 1; } cout<<L<<endl; } return 0;}
0 0
- UVAlive 4683 Find The Number
- UVALive 4683 Find The Number(容斥原理)
- UVALive 4683 Find The Number(容斥+二分)
- UVA 4683 - Find The Number
- UVALive 5072 Find the Multiples
- uvaLive 2701 Find The Multiple
- UVALive - 2701 Find The Multiple
- Find the Prime Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- initramfs的运行过程
- poj1716 Integer Intervals--单源最短路径&差分约束
- 深度优先搜索算法的通用解法
- URAL 1786 Sandro's Biography
- Ubuntu 12.04安装arm-linux-gcc-4.4.3
- UVAlive 4683 Find The Number
- 引jquery入库
- qt :-1: 错误:cannot open output file debug\test2.exe: Permission denied 类似错误
- spring--注解
- secure CRT 登陆虚拟机中ubuntu 12详解
- HDU 题目分类
- 基于FPGA的多目标图像跟踪技术
- 折半查找算法
- TCP的三次握手(建立连接)和四次挥手(关闭连接)